prototype方式继承
javascript的继承和java不同,不是基于class实现,而是基于prototype实现的。
function Animal(nAge){ this.age = nAge;}Animal.prototype.eat = function(){ // eat something};function Cat(sName){ this.name = sName;}Cat.prototype = new Animal();Cat.prototype.constructor = Cat;var cat = new Cat("kitty");cat.eat();Cat.prototype.constructor = Cat;
Cat.prototype = new Animal();
Cat.prototype.constructor = Cat;
Cat.prototype = {};