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

Sampson picture Sampson · Jan 15, 2010 · Viewed 20.5k times · Source

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

Description: An empty function. (added in 1.4)

You can use this empty function when you wish to pass around a function that will do nothing.

Perhaps I'm missing something profound here, but what exactly is a practical use of passing around an empty function?

Code examples appreciated.

Answer

Christian C. Salvadó picture Christian C. Salvadó · Jan 15, 2010

This function was proposed due to performance issues on embedded systems when using $.ajax, reported on the jQuery-Dev mailing list. You can see the thread.

Basically, they preferred to introduce and use this single empty function, rather than declaring empty anonymous functions all around.

Now this function is internally used in the ajax, event and offset modules.

You can give a look to the commit when it was introduced also.