测试javascript继承

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

<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
分享
返回顶部
顶部