AbstractDuck={
create: function(){return Object.create(this)},
extend: function(src){
for(var i in src){
if(!src.hasOwnProperty(i)) return this
this[i]=src[i]
}
return this
},
swim: function(){console.log("I am swimming")}
}
RealDuck=AbstractDuck.create().extend({
quack: function(){console.log("My name is "+this.name+", quack, quack.")}
})
RubberDuck=AbstractDuck.create().extend({
quack: RealDuck.quack
})
WoodDuck=AbstractDuck.create()
;[
RealDuck.create().extend({name: "Donald"}),
RubberDuck.create().extend({name: "RubberDonald"}),
WoodDuck.create().extend({name: "Woody"})
].forEach(function(duck){if(duck.quack) duck.quack()})
//My name is Donald, quack, quack.
//My name is RubberDonald, quack, quack.