Javascript??л??????
???????????? ???????[ 2012/10/31 10:17:28 ] ????????
????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();
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11