如何在javascript函数中创建超级

tia*_*mac 9 javascript jquery

就像在这个例子中:

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)

我怎样才能做到这一点?

Edu*_*sta 0

我在互联网上看到了很多使用这个的例子(包括基于 jQuery 的):

var that = this;
var sayName = function() {
   alert(that.name);
}
Run Code Online (Sandbox Code Playgroud)