JS中面向对象的实现:
function Person(name,color){ this.name = name; this.color = color; } Person.prototype.showName = function(){ alert(this.name); } Person.prototype.showColor = function(){ alert(this.color); } function Worker(name,color,job,age){ Person.apply(this,arguments) this.job = job; this.age = age; } for(var i in Person.prototype){ Worker.prototype = Person.prototype; } Worker.prototype.showAge = function(){ alert(this.age); }; var workMan = new Worker(‘sl‘, ‘red‘,‘coders‘,34); workMan.showName(); //sl workMan.showColor(); //red workMan.showAge(); //34
面向对象继承属性 方法,添加属性和方法
原文:http://www.cnblogs.com/swl267/p/5244718.html