I'm using a bit of code that I found on the web to manufacture objects. It allows me to organize objects into namespaces, and keeps my code pretty readable.
var TEST = {};
//The next two lines is the stuff that I found on the web. I think I
//basically understand what's going on here, but maybe I'm implementing it
//incorrectly?
TEST.testObj = function () { this.initialize.apply(this, arguments); };
TEST.testObj.prototype = {
a: null,
b: [],
initialize: function(a) {
this.a = a;
this.b[0] = a;
}
}
t1 = new TEST.testObj(1);
t2 = new TEST.testObj(2);
alert(t1.a + ', ' + t2.a);
alert(t1.b + ', ' + t2.b);
So, basically t1.a, a primitive, retains it's value when t2 is instantiated. But t1.b changes. It seems like both instances are simply referencing a single array, but creating unique primitives.