Possible Duplicate:
Is it possible to gain access to the closure of a function?
Please have a look at this code: http://jsfiddle.net/FH6pB/1/
(function($) {
var o1 = {
init: function() { alert('1'); },
}
var o2 = {
init: function() { alert('2'); },
}
}(jQuery));
(function($) {
var o3 = {
init: function() { alert('3'); },
}
o2.init();
}(jQuery));
o1.init();
o2.init();
I have 3 object in 2 different "scopes" (I don't know if it's the right word to use here, but I guess you understand the meaning).
As you probably know, I can't access the objects' function from either outside or other "scope" (non of the o.init();
will work).
Why does it happen? Is there a way to change it?
I know I can just put the code in one scope and it will work well, but what if I have scopes in separate JS file?
Thanks from advance, Ben