我們的志工尚未將本文翻譯為 正體中文 (繁體) 版本。加入我們,幫忙翻譯!
您也可以閱讀本文的 English (US) 版本。

Message

SyntaxError: missing } after function body

Error type

SyntaxError

What went wrong?

There is a syntax mistake when creating a function somewhere. Also check if any closing curly brackets or parenthesis are in the correct order. Indenting or formatting the code a bit nicer might also help you to see through the jungle.

Examples

Forgotten closing curly bracket

Oftentimes, there is a missing curly bracket in your function code:

var charge = function() {
  if (sunny) {
    useSolarCells();
  } else {
    promptBikeRide();
};

Correct would be:

var charge = function() {
  if (sunny) {
    useSolarCells();
  } else {
    promptBikeRide(); 
  }
};

It can be more obscure when using IIFE, Closures, or other constructs that use a lot of different parenthesis and curly brackets, for example.

(function() { if (true) { return false; } );

Oftentimes, indenting differently or double checking indentation helps to spot these errors.

(function() {
  if (true) {
    return false;
  }
});

See also

文件標籤與貢獻者

 此頁面的貢獻者: fscholz
 最近更新: fscholz,