Hello
I'm trying a few different approaches to Javascript inheritance at the moment. I have the following code:
('borrowed' from http://www.kevlindev.com/tutorials/javascript/inheritance/index.htm)
KV = {};
KV.extend = function(subClass, baseClass) {
function inheritance() {}
inheritance.prototype = baseClass.prototype;
subClass.prototype = new inheritance();
subClass.prototype.constructor = subClass;
subClass.baseConstructor = baseClass;
subClass.superClass = baseClass.prototype;
}
function GridView() {
var _ownerElement;
}
GridView.prototype.getOwnerElement = function() {
return this._ownerElement;
}
GridView.prototype.setOwnerElement = function(ownerElement) {
this._ownerElement = ownerElement;
}
GridView.prototype.initialize = function() {
this.setOwnerElement('test');
}
function StreetGridView(dataURL, ownerElement) {
StreetGridView.baseConstructor.call(this);
StreetGridView.superClass.initialize();
StreetGridView.superClass.setOwnerElement(ownerElement);
}
// subclass StreetGridView
KV.extend(StreetGridView, GridView);
Now, when I create an instance of StreetGridView, I can call getOwnerElement() on it no problem. Everything works as expected.
HOWEVER
When I create ANOTHER instance, any changes made to instance 2 are reflected back in instance 1.
I know this is the main problem with using prototypes as the share instance information. I've been racking my brains this morning but wondered if there was someone out there who could point me in the right direction!
Thanks