Can anyone explain why do I get different values of self and this? Where self is a reference to this.
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();
I've been using self on project and it's my first time to have this issue.
func
, it seems likeself
points to theParent
, butthis
points to theChild
. – Beaded