This is going to be a newbie question, but as simple as the answer may be, I am struggling to understand the concept. Any feedback will be greatly appreciated
This is a simplified version of my problem
var x=(function(){
this.load=function(){
alert("this is x load");
};
return this
})();
var y=(function(){
this.load=function(){
alert("this is y load");
};
return this
})();
x.load();
y.load();
Execution result is
alert(this is y load) for both x.load and y.load
My question
Why is x accessing the var y.load? I thought that bc each load function is wrapped in its own self-invoking anonymous function it is only accessible by the corresponding variable
Also, to ahieve what i want(to have .load() be w/in the scope of the variable), what would be the best way to declare each of these objects.( I only need 1 instance of each x and y)
I want to stick to self-involing bc inside these functions, i plan to have jquery document ready event-handlers which i want set immediately.