I don't want to pollute the prototype of objects with all my library's methods. I want to hide them inside a __namespace property.
When you try to access an object property, if it is undefined, it will look up the prototype chain like so
a.c -> a.prototype.c -> a.prototype.prototype.c ..
I would like to achieve
a.__namespace.c -> a.prototype.__namespace.c, a.prototype.prototype.__namespace.c ...
Exemple :
function A(){};
A.prototype.__namespace = {};
A.prototype.c = 2; // normal
A.prototype.__namespace.c = 2; // inside namespace
var a = new A();
a.__namespace = {};
console.log(a.c) // prints 2
console.log(a.__namespace.c); //undefined. Would like to print 2.
Is there a javascript functionality that allows this other than creating it like :
function NameSpace(){}
NameSpace.prototype.c = 3;
var a = new A();
a.__namespace = new NameSpace();
console.log(a.__namespace);
Check this fiddle.