= = can simplify the invocation of the previous callback function, specifically:
In the future, almost all callback functions can be simplified by using the arrow function
Like what:
1. All callback functions can: go to function change =
2. If the function body has only one sentence: can omit {}
If this sentence is still return, you can omit return
3. If there is only one parameter: can omit ()
However, if there are no parameters, you must leave the empty ()
Larger use: Arrow functions are shared with the same this--in and out of bind
Special: If you do not want to share this inside and outside, you cannot use the arrow function
such as the event handler function:
Elem.addeventlistener ("click", Function () {This->elem})
Elem.addeventlistener ("click", () =>{this-> not Elem})
Workaround:
Elem.addeventlistener ("Click", e=>{E.target->elem})
vararr=[12,2,123,23,1,3]; //Arr.sort (function (A, b) {return -a-B;})Arr.sort (A, b) =>a-b); Console.log (arr); varNewarr=arr.map (val=>val*2); Console.log (String (NEWARR)); varbob={sname:"Bob", friends:["Jack", "Rose", "Tom", "Jerry"], Intr () {//This->bob This. Friends.foreach (Val=Console.log ( This. sname+ "Know" +val)); }} bob.intr (); varBtns=document.getelementsbytagname ("button"); //This->window for(varI= 0,len=btns.length;i<len;i++) {Btns[i].addeventlistener ("Click", //() =>alert (this.innerhtml)//ErrorE=>alert (e.target.innerhtml))}
= = applied in JS callback function