继承于原型

function Employee () {

this.name = "";

this.dept = "general";

this.age = 19;

}

//Employee.prototype.age = 19;

function Manager() {

Employee.call(this);

this.reports = [];

}

Manager.prototype = Object.create(Employee.prototype);

var sally = new Manager();

//alert(sally.dept); //general

Employee.prototype.age =210;

//alert(sally.age);//210

function Engineering(){

this.dept = "engineering";

this.machine = "mach";

}

Engineering.prototype = Object.create(Manager.prototype);

var chris = new Engineering();

alert(chris.__proto__ == Engineering.prototype);//true

chris.__proto__.__proto__ == Manager.prototype;//true

chris.__proto__.__proto__.__proto__ == Employee.prototype;//true

chris.__proto__.__proto__.__proto__.__proto__ == Object.prototype;//true

chris.__proto__.__proto__.__proto__.__proto__.__proto__ == null;//true

猜你喜欢

转载自blog.csdn.net/zhangting8_/article/details/83868129