function Person(name,age,position){
this.name = name;
this.age = age;
this.position = position;
this.displayInfo = function(){
alert("[Name: "+ this.name +"] [Age: "+this.age+"] [position: "+this.position+"]");
}
}
function Programmer(name,age,position){
// this.tempObject = Person; //声明临时指针指向父类
// this.tempObject(name,age,position);
/*
相当于调用函数Person(...),调用父类构造函数,没有new,this指向子类,
进而有:this.displayInfo = function()
相当于:this.person = function(){
this.display = function(){...}
}
*/
// delete this.tempObject; //删除临时指针,防止通过tempObject引用覆盖超类Person的属性和方法
Person.call(this , name,age,position);
}
var oBpmProgrammer = new Programmer("Kevin",24,"BPM Programmer");
var oBopReportDeveloper = new Programmer("Witkey",25,"BOP Report Developer");
oBpmProgrammer.displayInfo(); //[Name: Kevin] [Age: 24] [position: BPM Programmer]
oBopReportDeveloper.displayInfo(); //[Name: Witkey] [Age: 25] [position: BOP Report Developer]