测试javascript继承

原创
2015/08/21 11:09
阅读数 59

<script>

//test of pseudoclassical


function Animal(name){

this.name = name;

this.say = function(){

return "nonting";

};

this.introduce = function(){

console.log(this.name + " says " + this.say());

}

}


function Cat(){

this.say = function(){

return "Meow";

}; 

}


Cat.prototype = new Animal("Cat");


function Dog(){

this.say = function(){

return "Wow";

}

}


Dog.prototype = new Animal("Dog");


var animals = [new Cat(), new Dog()];


animals.forEach(function(element, index, array){

element.introduce();

});

</script>


展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部