var Pet = JSClass({
name: function(name) {
if (typeof name === 'undefined') {
return this.name;
}
this.name = name;
}
});
var Animal = Class({
eat: function() {
this.fed = true;
},
drink: function() {
this.thirsty = false;
}
});
var Dog = JSClass({
}).mixin(Pet, Animal);
var pluto = new Dog();
pluto.eat();
pluto.name('pluto');
console.log(pluto.name());//pluto
console.log(pluto.thirsty);//false
So I am a bit confused about this example (and a newbie so please forgive if the following is silly).
First, I think that 'var Animal = Class' should be var Animal =JSClass. If not, can you explain?
Second, as I understand it, a class provides methods that are inherited. So in the case of Pluto, he inherits the method eat via the mixin containing Animal. You then call the method pluto.eat() which assigns the property eat to Pluto. But you did not do that for drink. So shouldn't 'console.log(pluto.thirsty);//false' return 'undefined'?