5.11 Disallowed features

5.11.1 with

Do not use the with keyword. It makes your code harder to understand and hasbeen banned in strict mode since ES5.

5.11.2 Dynamic code evaluation

Do not use eval or the Function(…string) constructor (except for codeloaders). These features are potentially dangerous and simply do not work inCSP environments.

5.11.3 Automatic semicolon insertion

Always terminate statements with semicolons (except function and classdeclarations, as noted above).

5.11.4 Non-standard features

Do not use non-standard features. This includes old features that have beenremoved (e.g., WeakMap.clear), new features that are not yet standardized(e.g., the current TC39 working draft, proposals at any stage, or proposed butnot-yet-complete web standards), or proprietary features that are onlyimplemented in some browsers. Use only features defined in the current ECMA-262or WHATWG standards. (Note that projects writing against specific APIs, such asChrome extensions or Node.js, can obviously use those APIs). Non-standardlanguage “extensions” (such as those provided by some external transpilers) areforbidden.

5.11.5 Wrapper objects for primitive types

Never use new on the primitive object wrappers (Boolean, Number, String,Symbol), nor include them in type annotations.

Disallowed:

  1. const /** Boolean */ x = new Boolean(false);
  2. if (x) alert(typeof x); // alerts 'object' - WAT?

The wrappers may be called as functions for coercing (which is preferred overusing + or concatenating the empty string) or creating symbols.

Example:

  1. const /** boolean */ x = Boolean(0);
  2. if (!x) alert(typeof x); // alerts 'boolean', as expected

5.11.6 Modifying builtin objects

Never modify builtin types, either by adding methods to their constructors or totheir prototypes. Avoid depending on libraries that do this. Note that theJSCompiler’s runtime library will provide standards-compliant polyfills wherepossible; nothing else may modify builtin objects.

Do not add symbols to the global object unless absolutely necessary(e.g. required by a third-party API).

5.11.7 Omitting () when invoking a constructor

Never invoke a constructor in a new statement without using parentheses ().

Disallowed:

  1. new Foo;

Use instead:

  1. new Foo();

Omitting parentheses can lead to subtle mistakes. These two lines are notequivalent:

  1. new Foo().Bar();
  2. new Foo.Bar();