測試javascript繼承

<script>this

//test of pseudoclassicalspa


function Animal(name){prototype

this.name = name;ip

this.say = function(){element

return "nonting"; it

};io

this.introduce = function(){console

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

}class

}


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>

相關文章
相關標籤/搜索