Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

SyntaxError: arguments is not valid in fields

The JavaScript exception "SyntaxError: arguments is not valid in fields" occurs when thearguments identifier is read in a class field initializer or in a static initialization block, outside of a non-arrow function.

Message

SyntaxError: 'arguments' is not allowed in class field initializer or static initialization block (V8-based)SyntaxError: arguments is not valid in fields (Firefox)SyntaxError: Unexpected identifier 'arguments'. Cannot reference 'arguments' in class field initializer. (Safari)

Error type

What went wrong?

A class field initializer expression or a class static initialization block does not havearguments in its scope. Trying to access it is a syntax error.

  • This is true even ifarguments is bound in a parent scope (such as when the class is nested in a non-arrow function).
  • A non-arrow function declared within this scope will still bind its ownarguments and read it normally.

Examples

js
function makeOne() {  class C {    args = { ...arguments }; // SyntaxError: arguments is not valid in fields  }  return new C();}
js
let CArgs;class C {  static {    CArgs = arguments; // SyntaxError: arguments is not valid in fields  }}
js
class C {  args = {};  constructor() {    this.args = arguments; // You can use arguments in constructors  }  myMethod() {    this.args = arguments; // You can also use it in methods  }}
js
function makeOne() {  const _arguments = arguments;  class C {    args = { ..._arguments }; // Only the identifier is forbidden  }  return new C();}

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp