/* * ArrowFunction */
function sum() {
    return x + y;
};
// const sum=(x,y)=>{
// return x+y;
/ /};
// If the body of a function has only one sentence but return blah blah blah, omit the curly braces and return
// const sum =(x,y)=>x+y;

// If only one parameter can be omitted, the parentheses can be omitted
// const sum = x => x+10;

/* function fn(x) { return function (y) { return x + y; } } const fn = x => y => x + y; console.log(fn(10)(20)); * /
/ * / / = = = = = = = = = = = = = no arrow function arguments, but can use the remaining in the ES6 operators to obtain const argument set fn = (... params) => { // console.log(arguments); //Uncaught ReferenceError: arguments is not defined console.log(params); //[10, 20, 30] // console.log(x,params); // @1 [20, 30] // @2 params () {// @1 [20, 30] // @2 params () {// @1 [20, 30]}; fn(10, 20, 30); * /

// ======== the arrow function does not have its own THIS; the THIS that appears in the function is the THIS of its parent context
/* let obj ={name:'zhufeng', // equalize to "fn:function(){}", this->obj let self=this; SetTimeout (function(){// this->obj This is window unless we (or the browser) do something special to trigger the callback. console.log(this.name); }, 1000); }}; obj.fn(); * /

/* let obj ={name:'zhufeng', fn(){//this-> obj setTimeout(()=>{//this-> no, console.log(this.name); }, 1000); }}; obj.fn(); * /

/* / let obj ={name:'zhufeng', fn ()=>{this-> this:'window' console.log(this.name); }}; obj.fn(); * /

// ======== arrow functions do not have a prototype property, so cannot be executed by new



Copy the code