The first four items are not the arrow function, the last few items are compared with the normal function, please correct.

1. Arrow functions cannot be Generator functions and the yeild keyword cannot be used.

The yield keyword usually cannot be used in arrow functions (unless nested within an allowed function). Therefore, arrow functions cannot be used as function generators.

2. Arrow functions do not have prototype objects.

var Foo = () = > {};
console.log(Foo.prototype); // undefined
Copy the code

3. Arrow functions do not have super.

No Prototype can access prototype properties through super, so arrow functions don’t have super either

4. Arrow function does not have new.target.

ES6 uses new.target to determine whether to use new. Arrow functions cannot be created using new

5. This points to something different

The arrow function’s this always refers to its context’s this, and no method can change its reference, such as call(), bind(), apply() vs in normal functions, this always refers to the object on which it was called; if used as a constructor, this refers to the object instance being created; In strict mode function calls, this refers to undefined; If the function is a method of an object, its this pointer points to that object

var b = 11 
function a(h) { 
  let b = 10 
  let f = () = > {
    let result = h + this.b 
    return result 
  } 
  console.log(f()) / / 14
  console.log(f.call(b, h)) / / 14
} 
a(3)
Copy the code

6. The creation methods are different

TypeError: XXX is not a constructor

var Foo = () => {};
var foo = new Foo();
Copy the code

7. Only anonymous functions

Normal functions can have anonymous functions or named functions, but arrow functions are anonymous

Arguements are not bound to function arguments. Use rest arguments… To solve

Each ordinary function call has a Arguments object to store the arguments that are actually passed. But the arrow function does not have this object.

var arguments1 = [1.2.3];

var arr = () = > arguments1[0];

arr() / / 1

function foo(n) {
  var f = () = > arguments[0] + n; 
  Arguments [0] is n, the first argument passed to foo
  return f();
}

foo(1); / / 2
foo(2); / / 4
foo(3); / / 6
foo(3.2);/ / 6

Copy the code
function foo(arg) {
  var f = (. args) = > args[0];
  return f(arg);
}
foo(1); / / 1

function foo(arg1,arg2) {
    var f = (. args) = > args[1];
    return f(arg1,arg2);
}
foo(1.2);  / / 2


Copy the code