【发布时间】:2011-07-22 17:34:37
【问题描述】:
我对以下代码中的“this”关键字感到困惑,有两个“this”:
var Foo = function(string){
this.name=string // 1st-this
}
Foo.prototype.get_name = function(){
return this.name // 2nd-this
}
var myFoo = new Foo('John')
the_name=myFoo.get_name()
'the_name' 等于'John',原型方法通过返回this.name获取名字。但是谁能给我解释一下 1st-this 和 2nd-this,它们代表什么?
【问题讨论】:
标签: javascript this prototype