一.函数的声明
function test(){
}
1.命名函数表达式
var test = function abc(){
}
document.write(test.name);//test.name=abc
2.匿名函数表达式
var test = function(){
}
document.write(test.name);//test.name=test
二.函数的组成
函数中的参数:分为型参和实参
在函数中会有一个arguments的数组来存放型参
注:在javascript中型参可以不等于实参
function test(a,b,c){
document.write(arguments[0]);//1
document.write(arguments[1]);//2
document.write(arguments[2]);//3
}
test(1,2,3);
function test(a,b){
document.write(a+b);//3
}
test(1,2,3);
当型参和实参的位置能够对应的时候,型参和argument的一一对应的,也是形参改变的同时arguments也会改变,arguments改 变的同时形参也会改变。
function test(a,b){
arguments[0]=3;
document.write(a);//3
b=4;
document.write(arguments[1]);//4
}
test(1,2);
如果没有对应,就会答应undefined
function test(a,b){
b=4;
document.write(arguments[1]);//undefined
}
test(1);