What is this: $ (function () {?

Is it basically the same as $(document).ready, or is it only working to provide jQuery?

Maybe something else I do not see?

+3
source share
3 answers

Yes. $(function() { ... });is short for $(document).ready(function() { ... });.

See the jQuery documentation for this handler .

+13
source

This is the same as

$(document).ready(function() {});

As far as I know, there is no difference.

+1
source

This is from jQuery 1.5.1 source. The abbreviation $ (function () {}) uses an internal ready-made function.

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

Source: https://habr.com/ru/post/1794958/


All Articles