//javascript通过将构造器函数与原型对象相关联的方式来实现继承
function Employee(name,dept){
this.name=name;
this.dept = dept;
}
function Manager(reports){
this.reports = reports;
}
Manager.prototype=new Employee();
function Employee(){
this.name = "";
this.dept = "general";
}
function Manager(){
this.reports = [];
}
Manager.prototype = new Employee;
function WorkerBee(){
this.projects = [];
}
WorkerBee.prototype=new Employee;
function SalesPerson(){
this.dept = "sales";
this.quota = 100;
}
SalesPerson.prototype=new WorkerBee;
function Engineer(){
this.dept="engineering";
this.machine="";
}
Engineer.prototype=new WorkerBee;
var jim = new Employee();
console.log(jim.name);
console.log(jim.dept);
var sally = new Manager;
console.log(sally.name);
console.log(sally.dept);
console.log(sally.reports);
var mark = new WorkerBee;
console.log(mark.name);
console.log(mark.dept);
console.log(mark.projects);
var fred = new SalesPerson;
console.log(fred.name);
console.log(fred.dept);
console.log(fred.projects);
console.log(fred.quota);
var jane = new Engineer;
console.log(jane.name);
console.log(jane.dept);
console.log(jane.projects);
console.log(jane.machine);
转载请注明原文地址: https://ju.6miu.com/read-1203646.html