您的位置:首页 > Web前端 > JavaScript

js 继承 实例图示详解

2016-08-25 20:27 471 查看
</pre><pre name="code" class="javascript"><script type="text/javascript">
function Animal(name,age){
this.name = name;
this.age = age;

this.action = function(){
console.log('animal action');
}
}

Animal.prototype.sleep = function(){
console.log('animal sleep');
}

Animal.prototype.eat = function(){
console.log('animal eat');
}

function Bird(name){
this.name = name;
}

Bird.prototype = new Animal('animalname',0);
Bird.prototype.constructor = Bird;

var birdObject = new Bird('乌鸦');

</script>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  js 继承详解 图示