任何人都可以解释为什么我得到不同的自我和这个值?自我是对此的参考.
function Parent(){
var self = this;
this.func = function(){
// self.a is undefined
// this.a is 'Test'
console.log(self.a, this.a);
}
}
function Child(x){
this.a = x;
}
Child.prototype.__proto__ = new Parent;
var ch = new Child('Test');
ch.func();
Run Code Online (Sandbox Code Playgroud)
我一直在项目上使用self,这是我第一次遇到这个问题.