I was going through one Backbone.js
plugin in which I found the below piece of code.
callbacks : {
search : $.noop,
valueMatches : $.noop
}
What is the $.noop()
function doing here?
I was going through one Backbone.js
plugin in which I found the below piece of code.
callbacks : {
search : $.noop,
valueMatches : $.noop
}
What is the $.noop()
function doing here?
- 1 it is an empty function, which doesn't do anything, this is used so that you don't have to check whether the option is undefined before calling it – Arun P Johny Commented Feb 5, 2014 at 9:06
-
2
Why not using
function() {}
directly? Because there is already a cached one used by jQuery already. :D – stevemao Commented Jun 5, 2015 at 5:30 - 1 Possible duplicate of What real purpose does $.noop() serve in jQuery 1.4? – Pang Commented Sep 19, 2016 at 7:57
1 Answer
Reset to default 9$.noop
is an empty function so in your case it's returning an empty function
You can use this empty function when you wish to pass around a function that will do nothing.
This is useful for plugin authors who offer optional callbacks; in the case that no callback is given, something like jQuery.noop could execute.
Documentation found here : http://api.jquery./jquery.noop/