Here is my code showing that "var B" is targeting a global variable:
function koo(){
console.log( this.B );
}
var sampleObj = {
B: 2,
koo: koo
};
var xyz = sampleObj.koo;
var B = "It's global";
xyz();
Here is my code showing that "var B" is targeting a global variable:
function koo(){
console.log( this.B );
}
var sampleObj = {
B: 2,
koo: koo
};
var xyz = sampleObj.koo;
var B = "It's global";
xyz();
you are not executing it like sampleObj.koo()
, and taking a direct reference to xyz
so it is impossible to know from where it taken from, it cab be associated with so many object (or even not to anyone) with the same reference. if you want to invoke some function (reference you have) from outside in the monitor of a object, try calling xyz.call(sampleObj)
instead