function Animal(name) { this.name = name; } Animal.prototype.eat = function(food) { console.log("food"); }; Animal.prototype.getName = function() { return this.name; }; var a = new Animal('hello'); a.eat("world"); console.log(a.getName()); console.log(a.name); function Ferret(){} Ferret.prototype = new Animal();//Ferret.prototype.__proto__ = Animal.prototype; Ferret.prototype.type = "Domestic"; Ferret.prototype.eat = function (food) { Animal.prototype.eat.call(this,food); // console.log("Ferret Eat:.."); }; var f = new Ferret(); f.eat();
原文地址:http://blog.csdn.net/haifengzhilian/article/details/26683221