基于原型的类继承

 1 var Animal = function() {};
 2 
 3 Animal.prototype.breath = function() {
 4     console.log('breath');
 5 };
 6 
 7 var Dog = function() {};
 8 
 9 //Dog继承了Animal
10 Dog.prototype = new Animal;
11 
12 Dog.prototype.wag = function() {
13     console.log('wag tail');
14 };
15 
16 var dog = new Dog;
17 dog.wag();
18 dog.breath(); //继承的属性

 

日志: wag tail
日志: breath

posted @ 2012-07-23 13:18  小猩猩君  阅读(120)  评论(0编辑  收藏  举报