箭头函数与普通函数的区别

82 阅读1分钟

(1)箭头函数比普通函数更加简洁 (2)箭头函数没有自己的this 箭头函数不会创建自己的this, 所以它没有自己的this,它只会在自己作用域的上一层继承this。所以箭头函数中this的指向在它在定义时已经确定了,之后不会改变 (3)箭头函数继承来的this指向永远不会改变 (4)call()、apply()、bind()等方法不能改变箭头函数中this的指向

var id = 'Global';
let fun1 = () => {
    console.log(this.id)
};
fun1();                     // 'Global'
fun1.call({id: 'Obj'});     // 'Global'
fun1.apply({id: 'Obj'});    // 'Global'
fun1.bind({id: 'Obj'})();   // 'Global'

(5)箭头函数不能作为构造函数使用 (6)箭头函数没有自己的arguments (7)箭头函数没有prototype