测试javascript继承

<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>


你可能感兴趣的:(测试javascript继承)