function extend(target, source) {
var names = Object.getOwnPropertyNames(source)
, length = names.length;
for (var i = 0; i < length; ++i) {
var desc = Object.getOwnPropertyDescriptor(source, names[i]);
Object.defineProperty(target, names[i], desc);
}
return target;
}
function inherit(Child, Parent) {
var proto = Object.create(Parent.prototype);
proto.constructor = Child;
proto.parent = Parent.prototype;
extend(proto, Child.prototype);
Child.prototype = proto;
}
function Animal(name, sound) {
this.name = name;
this.sound = sound;
}
Animal.prototype.say = function() {
console.log("%s says %s", this.name, this.sound);
};
function Cat() {
this.parent.constructor.call(this, "cat", "meow");
}
Cat.prototype.lick = function(what) {
console.log("%s licking his %s", this.name, what);
};
inherit(Cat, Animal);
var cat = new Cat;
cat.say();
cat.lick("balls");