1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| function Person(name, sex) { this.name = name; this.sex = sex; } Person.prototype.showName = function() { alert(this.name); } Person.prototype.showSex = function() { alert(this.sex); } var p1 = new Person('char', '男'); p1.showName(); function Worker(name, sex, job){ Person.call(this, name, sex); this.job = job; }
for (var i in Person.prototype) { Worker.prototype[i] = Person.prototype[i]; } Worker.prototype.showJob = function(){ alert(this.job); } var w1 = new Worker('max', '男', '打杂的'); w1.showJob();
|