JavaScript style for optional callbacks

后端 未结 10 1721
日久生厌
日久生厌 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:36

    If the criteria for running the callback is that whether its defined or not, then you're fine. Also, I suggest to check if its really a function in addition.

提交回复
热议问题