Arrow function - jellyfish-tom/TIL GitHub Wiki

[SOURCES]

Two factors influenced the introduction of arrow functions:

  1. shorter functions
  2. no existance of this keyword.

Characteristics of an arrow function

  • arrow function does not have its own this; the this value of the enclosing lexical context is used i.e. Arrow functions follow the normal variable lookup rules. So while searching for this which is not present in current scope they end up finding this from its enclosing scope
  • given that this comes from the surrounding lexical context, strict mode rules with regard to this are ignored
  • arrow functions do not have their own this. Methods call() or apply() can only pass in parameters. thisArg is ignored.
  • arrow functions do not have their own arguments object as well
  • arrow functions cannot be used as constructors and will throw an error when used with new.
var Foo = () => {};
var foo = new Foo(); // TypeError: Foo is not a constructor
  • arrow functions does not allow for yield keyword to be used inside them. As a consequence, arrow functions cannot be used as generators.