基于原型的类继承
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