We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
箭头函数没有自己的 this,也没有原型对象(prototype)
this
在 new 的时候,会生成一个 obj ,然后把 obj 的 proto 指向 构造函数的原型对象(prototype)上,来继承原型上的方法。因为尖头函数没有原型,所以报错。
function Person(name){ this.name = name } // 原型函数使用箭头函数,其中的this指向全局对象,而不会指向构造函数 // 因此访问不到构造函数本身,也就访问不到实例属性 Person.prototype.say = ()=>{console.log(this.name)}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
箭头函数没有自己的
this
,也没有原型对象(prototype)在 new 的时候,会生成一个 obj ,然后把 obj 的 proto 指向 构造函数的原型对象(prototype)上,来继承原型上的方法。因为尖头函数没有原型,所以报错。
箭头函数与普通函数的区别
The text was updated successfully, but these errors were encountered: