像一个超级例:如何使JavaScript函数
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();
});
我怎样才能做到这一点?
-1被调用:这是OP的原始代码。他正在寻求替代方案。 –
这是不公平的错误。他问道:“我想要在这个函数中访问'this' –
并且在上面这行中,他演示了你的解决方案并写道”我不想那样做“ –