1.
call()傳遞單個參數,apply()參數傳遞為數組參數
1
function?test(){
3
????alert(arguments.length);//實參的數目
4
?????alert(test.length);//行參的數目
5
}
2.callee返回當前方法的引用
3

4

5

1
function?test(){
3
????alert(arguments.callee.length);//行參的數目
4
?????//arguments.callee返回當前方法的引用,所以
5
?????//arguments.callee?==?test
6
????//所以實際上仍然偽test.length
7
}
3.call(),apply()
3

4

5

6

7

call()傳遞單個參數,apply()參數傳遞為數組參數
1
var?Class?=?{
2
??create:?function()?{
3
????return?function()?{
4
??????this.initialize.apply(this,?arguments);
5
????}
6
??}
7
}
8


2


3


4

5

6

7

8

?1
var?vehicle=Class.create();//vehicle為一個方法,所以可以有prototype屬性。返回的是一個構造函數。
?3
vehicle.prototype={
?4
????initialize:function(type){//這個方法在創建vihicle的對象的時候被調用
?5
????????this.type=type;
?6
????}
?7
????showSelf:function(){
?8
????????alert("this?vehicle?is?"+?this.type);
?9
????}
10
}
11
12
var?moto=new?vehicle("Moto");
13
moto.showSelf();
14

?3


?4


?5

?6

?7


?8

?9

10

11

12

13

14
