I am a newbie programmer and use namespace in Javascript.
There are something weird when programming . I have two "this" inside my namespace object , BUT there are two different results. One is represent Window Object , and the other is the namespace Object itself.
var namespace = {
A : function A(){},
B : function B(){
var b = function b(){
// "this" => Window Object
console.log(this);
};
b();
// "this" => namespace Object
console.log(this);
}
}
namespace.B();
I hope all this can represent the namespace Object. Is there something magic i can do?
Btw , I learned underscorejs library before. Is there any methods I can solve the problem with underscore library or merely pure javascript?
Thanks a lot.