标签:
//人类 function Person(name) { this.name = name; this.showName = function () { console.log("my name is " + name); } this.eat = function () { console.log("人是铁饭是钢..."); } } //白人 function WhitePerson(name) { this.temp = Person; this.temp(name); delete this.temp; this.color = function () { console.log("我们皮肤是偏白色的"); } } //黑人 function BlackPerson(name) { Person.call(this, name);//这个时候Person中的this指向的是BlackPerson的对象了 this.color = function () { console.log("我们皮肤是偏黑色的"); } } var wPreson = new WhitePerson("tom"); wPreson.showName(); var bPerson = new BlackPerson("john"); bPerson.showName();
以对象冒充的方式来实现js的继承
标签:
原文地址:http://www.cnblogs.com/yyq745201/p/4648680.html