js 怎么把方法当参数传递给方法?

JavaScript08

js 怎么把方法当参数传递给方法?,第1张

直接把方法名做为函数参数就可以<script>

function callfn(f)

{

f()

}

function test()

{

alert("this a test!")

}

callfn(test)

</script>

function test(msg){

alert(msg)

}

function a(b){

b()

}

a(test)

直接传函数名 比如funcB 在函数里面 直接执行funcB()

var b = function(){alert(1)}

var a = function(v1,v2){v2()}

a(1,b)