就像在这个例子中:
var teste = {name:'marcos'};
$(teste).each(function(){
var name = this.name; // i don't want to do that.
// i want to have access to 'this' inside this function (sayName)
var sayName = function(){
alert(name); // there is something like "super" in java? or similar way to do?
}
sayName();
});
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我在互联网上看到了很多使用这个的例子(包括基于 jQuery 的):
var that = this;
var sayName = function() {
alert(that.name);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1663 次 |
| 最近记录: |