Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

SyntaxError: Malformed formal parameter

이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 함께 해서 번역을 마치도록 도와 주세요!

Message

SyntaxError: malformed formal parameter (Firefox)

Error type

SyntaxError

What went wrong?

There is a Function() constructor with at least two arguments passed in the code. The last argument is the source code for the new function you're creating. All the rest make up your new function's argument list.

The argument list is invalid somehow. Perhaps you accidentally picked a keyword like if or var as an argument name, or perhaps there's some stray punctuation in your argument list. Or maybe you accidentally passed an invalid value, like a number or object.

OK, that fixed my problem. But why didn't you say that in the first place?

Admittedly the wording in the error message is slightly strange. "Formal parameter" is a fancy way of saying "function argument". And we use the word "malformed" because all Firefox engineers are huge fans of 19th-century Gothic horror novels.

Examples

Invalid cases

var f = Function("x y", "return x + y;");  
// SyntaxError (missing a comma)

var f = Function("x,", "return x;");  
// SyntaxError (extraneous comma)

var f = Function(37, "alert('OK')");
// SyntaxError (numbers can't be argument names)

Valid cases

var f = Function("x, y", "return x + y;");  // correctly punctuated

var f = Function("x", "return x;");

// if you can, avoid using Function - this is much faster
var f = function (x) { return x; };

See also

문서 태그 및 공헌자

 이 페이지의 공헌자: fscholz, jorendorff-moz
 최종 변경: fscholz,