Discuss / JavaScript / 我想请教一下把方法绑定到原型对象上的时候,为什么this不会绑进去

我想请教一下把方法绑定到原型对象上的时候,为什么this不会绑进去

Topic source

廖大好,大家好。 请问文中的代码:

Student.prototype.hello = function () {
    alert('Hello, ' + this.name + '!');
};

为什么不会把this绑定成Student.prototype呢。按理说,既然helloStudent.prototype 的方法。this指定的也应该是Student.prototype的呀。可为什么还能访问this.name呢。

不好意思,我发得太急了。我想通了,应该是谁调用就绑定谁。

廖雪峰

#3 Created at ... [Delete] [Delete and Lock User]

想通了就好


  • 1

Reply