0

I need to inject some extra data into $.getScript call, so it'll be availabe in ready handler, how do I do that?

// since it's called in a loop I need pass context into read handler
$.getScript(path, function (e2) {

};

in regular event handlers I can do do by passing the data as a second parameter and get it by e.data.* from within the event handler:

element.on("event", { extra: "data" }, function(e) { console.log(e.data.extra); });

which doesn't seem to work with $.getScript.

4

1 回答 1

1

.getSCript ()不提供该功能,但我认为您可以在此处使用闭包

前任:

for(var i = 0; i < x; i++){
    (function(idx){
        $.getScript(path, function (e2) {
            console.log(idx);
        });
    })(i);
}
于 2013-07-18T09:15:19.440 回答