I've used Dean Edward's base.js. I've used it for years, but the forum is dead so I thought I'd post here and see if anyone knew what's up. The following shows my issue:
var Animal = Base.extend({
name: "",
constructor: function(name){
this.name = name
},
getName: function(){
this.name
}
});
var Cat = Animal.extend({
prey: [],
getPrey: function(){return this.prey}
});
var Tiger = Cat.extend({});
var House = Cat.extend({});
var cats = [];
cats.push(new Tiger());
cats.push(new House());
cats[0].prey.push("dogs");
cats[1].prey.push("mice");
console.log(cats[0].getPrey());
console.log(cats[1].getPrey());
Basically, it creates a three level hierarchy(not sure if the eldest parent is necessary) with the middle parent having an array. When two separate child instances add something to their inherited array, it appears in both children. I would think that the above code would print in the console:
["dogs"]
["mice"]
Instead, it prints:
["dogs", "mice"]
["dogs", "mice"]
Am I missing something? It's possible that this is intentional, but from a typed language OO standpoint, I'm pretty sure that's not the way things are supposed to work. If anyone has a more elegant way of doing the above, I'm all ears.
As always, much obliged.