4
任何人都可以在js中告诉“this”这个关键字。我看了一些例子。有一点我不明白。这个关键字在js里面方法里的方法是什么逻辑?
A.B=function()
{
this.x(5); // this refers to prototype of A.B
}
A.B.prototype= {
x:function(p)
{ this.a(p); // this refers to prototype of A.B again
// but I expect that this refers to protoype of x ???
},
a:function(p){ return p;}
}
阅读此:http://javascript.crockford.com/private.html – hereandnow78
在这两种情况下,它指的是'B'实例,所以你可以调用'a' /'x'。 – pimvdb
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/这个 –