I am puzzled by some node.js behaviour, which is different fron Google Console.
Here is a simple code
var t = "GLOBAL";
var objet = {
t : "LOCAL1",
test : function() {
console.log(this.t,t);
}
};
var objet2 = {
t : "LOCAL2",
test : objet.test
};
var test = objet.test;
objet.test();
objet2.test();
test();
This code yiels different result.
In node.js, i have these results :
LOCAL1 GLOBAL
LOCAL2 GLOBAL
undefined 'GLOBAL'
In chrome console :
LOCAL1 GLOBAL
LOCAL2 GLOBAL
GLOBAL GLOBAL
I thought that calling directly the function binded to test.t, this would be binded to the global scope, it is the case in chrome, but node in node.js.
Note that if i remove the varin the first line, the node.js version give the same result.
So what is going one ? It seems that there is a scope in node.js that i am missing ? Does somebody have a clue ?