I want to call a javascript function within a protected scope and i can do it this way
var a = "Global a";
( function() {
var a = "Local a";
var alertA = function() {
alert(a);
}
alertA();
})();
This alerts “Local a” butt what i realy would like to do is to get the same result with an already declared function.
var a = "Global a";
var alertA = function() {
alert(a);
}
( function() {
var a = "Local a";
alertA();
})();
So my question is how can a call alertA with a different scope so the result would be “Local a”
The reason i would like to do this i want to call globally defined functions on different iframes and have global variabels like document and window point to the appropriate documents and windows for every specific iframe.
Let me put it as an answer:
I suggest you make the function accept
windowanddocumentas argument:In each frame, you can then take its
windowanddocumentas pass it to the function. For convenience, you can create a wrapper function in each frame, which does this for you: