1
2
3
4
5
6
7
8
9
10
|
function
add(a,b)
{
alert(a+b);
}
function
sub(a,b)
{
alert(a-b);
}
add.call(sub,3,1);
//4
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
function
test1(name,age)
{
this
.name=name;
this
.age=age;
}
/*定義一個學生類*/
function
test2(name,age,grade)
{
test1.apply(
this
,arguments);
this
.grade=grade;
}
//建立一個學生類
var
test3=
new
test2(
"uw3c"
,24,
"一年級"
);
//測試
alert(
"name:"
+test3.name+
"\n"
+
"age:"
+test3.age+
"\n"
+
"grade:"
+test3.grade);
|