1、没有自己的this、super、arguments和new.target绑定。
2、不能使用new来调用。
3、没有原型对象。
4、不可以改变this的绑定。
5、形参名称不能重复。
箭头函数中没有this绑定,必须通过查找作用域链来决定其值。 如果箭头函数被非箭头函数包含,则this绑定的是最近一层非箭头函数的this,否则this的值则被设置为全局对象。
var name = 'window';var student = {name: '若川',doSth: function(){// var self = this;var arrowDoSth = () => {// console.log(self.name);console.log(this.name);}arrowDoSth();},arrowDoSth2: () => {console.log(this.name);}}student.doSth(); // '若川'student.arrowDoSth2(); // 'window'
其实就是相当于箭头函数外的this是缓存的该箭头函数上层的普通函数的this。如果没有普通函数,则是全局对象(浏览器中则是window)。 也就是说无法通过call、apply、bind绑定箭头函数的this(它自身没有this)。而call、apply、bind可以绑定缓存箭头函数上层的普通函数的this。 比如:
var student = {name: '若川',doSth: function(){console.log(this.name);return () => {console.log('arrowFn:', this.name);}}}var person = {name: 'person',}student.doSth().call(person); // '若川' 'arrowFn:' '若川'student.doSth.call(person)(); // 'person' 'arrowFn:' 'person'
