Is this jQuery related, and what does this mean?

This question already has an answer here:

  • What does the exclamation mark do before the function? 9 answers

  • ! on a function(){}() simply flips (or negates) the value that's returned after immediately calling the function that's defined. Notice that immediately after the function definition, at the very last line, it says (window.jQuery) — that's passing jQuery as the argument to the function and calling it immediately.

    But in this case it doesn't appear to do anything important since the return value won't be used anyway. The function will still be executed though.

    Also, it says this at the top of the file:

    // NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
    // IT'S ALL JUST JUNK FOR OUR DOCS!
    // ++++++++++++++++++++++++++++++++++++++++++
    

    So that's evidence further that it's not meant to serve any real purpose.


    In this case, ! is being used because it's an operator, so the rest of the line will be treated as an expression rather than a statement. This is a way of writing an immediately invoked function expression. The more common idioms can be found here:

    Javascript immediately invoked function patterns

    链接地址: http://www.djcxy.com/p/17436.html

    上一篇: 在JS / jQuery中触发keypress / keydown / keyup事件?

    下一篇: 这是jQuery相关的,这是什么意思?