廖大好,大家好。 请问文中的代码:
Student.prototype.hello = function () { alert('Hello, ' + this.name + '!'); };
为什么不会把this绑定成Student.prototype呢。按理说,既然hello是Student.prototype 的方法。this指定的也应该是Student.prototype的呀。可为什么还能访问this.name呢。
Student.prototype
hello
this
不好意思,我发得太急了。我想通了,应该是谁调用就绑定谁。
想通了就好
Sign in to make a reply
蛮吉睡不醒
廖大好,大家好。 请问文中的代码:
为什么不会把this绑定成
Student.prototype
呢。按理说,既然hello
是Student.prototype
的方法。this
指定的也应该是Student.prototype
的呀。可为什么还能访问this.name呢。