JavaScript style for optional callbacks

后端 未结 10 1714
日久生厌
日久生厌 2020-12-02 07:30

I have some functions which occasionally (not always) will receive a callback and run it. Is checking if the callback is defined/function a good style or is there a better w

10条回答
  •  死守一世寂寞
    2020-12-02 07:45

    It can easilly be done with ArgueJS:

    function save (){
      arguments = __({callback: [Function]})
    .....do stuff......
      if(arguments.callback){
        callback();
      };
    };
    

提交回复
热议问题