ES6 ES6 arrow arrow function function summary

Foreword

  Arrow function expression syntax is more concise than function expressions, and not have their own this, arguments, superor new.target. Arrow function expression more suitable for those places that would otherwise require anonymous function, and it can not be used as a constructor.

  Small summary:

    1. Arrow no function arguments (recommended better syntax, the remaining alternative operator)
    2. arrow no function prototype property, can not be used as a constructor (can not be called using new)
    3. arrow does not own the this function, it this is a lexical, is quoted in this context, that this line of code you write when he had this arrow and function of this outer layer of the execution context bound

ES6 arrow function summary

1. The basic form of the function arrow

The original form of an anonymous function:

  function(params....){  }

ES6

var func = (num) => {...};
var func = () => {...};
var sum = (num1,num2) => {num1 + num2};
[1,2,3].map(x => {x * x});

   Deletion function (), add arrow =>, plus a selectable parameter without parentheses, brackets CSA no parameters, a plurality of parameters separated by a comma in parentheses

2.  arrow function this content

Arrow function this parent scope of this, this is not the time to call

Arrow function does not own this, arguments, super, new.target, which point to the corresponding variable outer function (non-arrow function).

 

Guess you like

Origin www.cnblogs.com/FondWang/p/12354453.html