箭头函数和普通函数的区别及不适用的场景
箭头函数不绑定 arguments,可以使用 ...args 代替 箭头函数没有 prototype 属性,不能进行 new 实例化 箭头函数不能通过 call、apply 等绑定 this,因为箭头函数底层是使用bind永久绑定this了,bind绑定过的this不能修改 箭头函数的this指向创建时父级的this 箭头函数不能使用yield关键字,不能作为Generator函数 const fn1 = () => { // 箭头函数中没有arguments console.log("arguments", arguments); }; fn1(100, 300); const fn2 = () => { // 这里的this指向window,箭头函数的this指向创建时父级的this console.log("this", this); }; // 箭头函数不能修改this fn2.call({ x: 100 }); const obj = { name: "poetry", getName2() { // 这里的this指向obj return () => { // 这里的this指向obj return this.name; }; }, getName: () => { // 1、不适用箭头函数的场景1:对象方法 // 这里不能使用箭头函数,否则箭头函数指向window return this....