I prefer not to clutter the object prototype with all my library's methods. My goal is to keep them hidden inside a namespace property.
When attempting to access an object property, if it is undefined, the script will search through the prototype chain in this manner:
a.c -> a.prototype.c -> a.prototype.prototype.c ..
My desired outcome is:
a.__namespace.c -> a.prototype.__namespace.c, a.prototype.prototype.__namespace.c ...
Example:
function A(){};
A.prototype.__namespace = {};
A.prototype.c = 2; // regular
A.prototype.__namespace.c = 2; // within namespace
var a = new A();
a.__namespace = {};
console.log(a.c) // outputs 2
console.log(a.__namespace.c); //undefined. I want it to output 2.
Is there a JavaScript feature that enables this besides creating it manually like so:
function NameSpace(){}
NameSpace.prototype.c = 3;
var a = new A();
a.__namespace = new NameSpace();
console.log(a.__namespace);
View this JS Fiddle snippet.