What real purpose does $.noop() serve in jQuery 1.4?

前端 未结 9 775
故里飘歌
故里飘歌 2020-12-30 19:01

Pouring over the release notes regarding jQuery 1.4, I came acrosss $.noop() which is:

Description: An empty function. (added in 1.4)

9条回答
  •  清歌不尽
    2020-12-30 19:07

    It can be useful if you have a function that supplies functions to other functions.

    Example: You have a List of data. Each item has a Button that does something. The "something" can be different for every item. You have a "FunctionFactory" that takes in the item and returns a function. If you don't want the button to do something for whatever reason, then the cleanest way could be to return an empty function, as that way you know that your Factory ALWAYS returns a function.

    I don't have a concrete example for jQuery, but I guess this could come in handy when used in an .each or .map block.

提交回复
热议问题