js 面向对象

时间:2014-05-26 05:21:44   收藏:0   阅读:345
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();



js 面向对象,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!