最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the use of jQuery.noop() function? - Stack Overflow

programmeradmin0浏览0评论

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?

Share Improve this question edited Feb 5, 2014 at 9:10 Vivek Jain 3,8896 gold badges32 silver badges47 bronze badges asked Feb 5, 2014 at 9:05 Renjith P NRenjith P N 4,2515 gold badges34 silver badges43 bronze badges 3
  • 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
Add a ment  | 

1 Answer 1

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/

发布评论

评论列表(0)

  1. 暂无评论