2017年3月3日 星期五

(js)的繼承

function Employee(name, dept) {
    this.name = name || "test";
    this.dept = dept || "general";
}

function WorkerBee(name, dept, projs) {
    this.base = Employee;
    this.base(name, dept);
    this.projects = projs || [];
}
WorkerBee.prototype = new Employee();

function Engineer(name, dept, projs, mach) {
    this.base = WorkerBee;
    this.base(name, dept, projs);
    this.dept = "engineering";
    this.machine = mach || "";
}
Engineer.prototype = new WorkerBee();
//////////////////////////////////////////////////////////////////


function Employee(name, dept) {
    this.name = name || "test";
    this.dept = dept || "general";
}

function WorkerBee(name, dept, projs) {
    Employee.call(this, name, dept);
    this.projects = projs || [];
}
WorkerBee.prototype = new Employee();

function Engineer(name, dept, projs, mach) {
    WorkerBee.call(this, name, dept, projs);
    this.dept = "engineering";
    this.machine = mach || "";
}
Engineer.prototype = new WorkerBee();