<script>
// 声明函数
function fun(a,b){
console.log("a :" + a + "b:" + b);
}
fun(1,2)
console.log("-----------------------------");
function fun1(a,b,c){
console.log("a :" + a + "b:" + b +"c:" + c);
}
// 实参传递给形参的值少的话 对应的时输出就是未定义的 undefined
fun1(3,4);
//实参可以是 对象 和 函数
function fun2(o){
console.log("name:" + o.name + "age:" + o.age);
}
var obj = {
name:"孙悟空",
age : 18
}
fun2(obj);
console.log(fun2);
console.log("---------------------------");
// 实参为函数
function fun3(){
console.log("我是fun3函数");
return "hello"
}
function fun4(f){
console.log("f:" + f);
}
// 调用函数对象 相当于直接使用函数对象
fun4(fun3);
console.log("--------------");
//调用函数 直接使用函数返回值
fun4(fun3());
console.log("======================");
// 匿名函数为实参
function fun5(a){
console.log("a:" + a);
}
fun5(function(){'console.log("我是匿名函数为实参")'});
</script>
js形参+实参
最新推荐文章于 2024-05-30 13:59:14 发布