代码如下:
function a(callback){
var m = 1;
var n = 2;
alert(callback(m,n));
}
function b(m,n){
return m+n;
}
a(b);
执行效果,弹出数字3
function main(callback, params) {
if (typeof callback === "function") {
callback.apply(null, params)
}
}
function b(p1, p2, p3) {
console.log(p1, p2, p3)
}
function c(p1, p2) {
console.log(p1, p2)
}
main(b, [1, 2, 3])
main(c, ["hh", "嘿嘿嘿"])