Tricky problems with prototypal inheritance.
Animal = function(){
this.offspring = [];
};
Dog = function(){}
Dog.prototype = new Animal()
var dog1 = new Dog()
var dog2= new Dog();
dog1.offspring.push(dog2);
assertEqual(dog2.offspring[0], dog2);
The offspring array will be shared by all dogs. This is why dog2 has dog2 as offspring. $.Class fixes this:
$.Class('Animal',{
init : function(){
this.offspring = [];
}
});
Animal('Dog')
The observer pattern:
var model = new $.Model({val : 'bar'})
model.bind('val', function(){
//called when val changes
})
model.attr('val', 'foo')