javaScript函数作为参数和函数作为返回值

1,函数作为参数

通常把函数作为参数叫做回调函数

function fn1(fn) {
  fn();
}
fn1(function(){
   console.log("哈哈"); 
});

2,函数作为返回值

function fn1() {
    return function(){
      console.log("呵呵");
    }
}
fn1()();//调用
    function test(){
      return function(){
        console.log('哈哈');
      };
    }
    var res=test();
    console.log(res);
    res();

猜你喜欢

转载自www.cnblogs.com/f2ehe/p/11655071.html