????Javascript???????Perl???????????????????????????????????汾?????????????????????????????Js????????????????????????????????????????????κ???????????????????OOP??OOP????????????????????????????????????????Щ????OOP???????????????????Js??????????

????Js????????????????μ?????????????????????????????????????e??????????????????????????????????????о??????????????????

?????????????e??

function A(name){
this.name = name;
this.sayHello = function(){alert(this.name+” say Hello!”);};
}
function B(name??id){
this.temp = A;
this.temp(name);        //????new A();
    delete this.temp;        //???????????temp??????????A??????????
     this.id = id;
this.checkId = function(ID){alert(this.id==ID)};
}

?????????????B?????????temp???????A???????????????????????????е?this??????B????????????????A????????????????A?????????????????this??????????B??????????????B?????A????????????????????????????temp?????????B?ж?A????????????????????????????????????temp??????????A?????????A?????????仯??

????????????????Js?汾???μ?????У???????????????????????this???л??????л????????????????????call??apply?????????????????????????????????汾?????????????????????????????????????????????????????call???????????????call???????e???С?

function Rect(width?? height){
this.width = width;
this.height = height;
this.area = function(){return this.width*this.height;};
}
function myRect(width?? height?? name){
Rect .call(this??width??height);
this.name = name;
this.show = function(){
alert(this.name+” with area:”+this.area());
}
}

????????Call???????????????????????????????????????????????滻???????

????call??thisOb??arg1?? arg2…??

???????????????e????У??????call????????????????????????????????????this???滻????myRect????????this??????????myRect???????????????????this?????????????????????????Rect??????????Rect???????????????????Rect????this?????????????????????????myRect???????С??????????call??apply?????????????ж???????????????????????????С?

????????e?????????????£??????????????У????????????????????????????????????????????ò????????????????????????????????????????OO?????????????????????+??????????????????????????????Щ?????????и?????????????????????????????ζ??????????????????????????????????????????????????????е????????????????????Js???????e?????????????е??????????????this?????????????????е???????????????????????????????????????????????????????????????????e????????prototype?????????????????????????????????????????????????????????????????????????????????????????μ???????????????????Js??к??????

???????????????

??????????з?????????????ν????????У??????????prototype??????????????????prototype???????????????????????????????к???У??????????????????????????????????????????????κβ??????????????????????????????

function Person(){
this.name = “Mike”;
this.sayGoodbye = function(){alert(“GoodBye!”);};
}
Person.prototype.sayHello = function(){alert(”Hello!”);};
function Student(){}
Student.prototype = new Person();