What does the jQuery() function in jQuery do?

后端 未结 4 652
臣服心动
臣服心动 2021-01-25 08:06

In this video there is a snippet of code that goes something like this:

if (jQuery) {jQuery(function() {
    // ...
})}

I\'ve never seen the

4条回答
  •  执念已碎
    2021-01-25 08:40

    $() is an alias for jQuery(), defined as:

    // Expose jQuery to the global object
    window.jQuery = window.$ = jQuery;
    

    http://code.jquery.com/jquery-1.4.js

    there is a special case defined when $() or jQuery() is called with the first argument being a function:

    // HANDLE: $(function)
    // Shortcut for document ready
    } else if ( jQuery.isFunction( selector ) ) {
        return rootjQuery.ready( selector );
    }
    

    sometimes $ can conflict with other libraries (like prototype) that define the same function, so if you call

    jQuery.noConflict();
    

    it will remove the $ alias, setting it back to the original value found, essentially:

    window.$ = _$;
    

提交回复
热议问题