Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery and Twitter Bootstrap function explanation

If you see the twitter's bootstrap application.js file that exists in all documents, you will notice something the following code:

!function( $ ) {
    ...
}( window.jQuery );

Could someone explain why this is the case for the first line of the code?

thanks

like image 368
user1290584 Avatar asked Mar 14 '26 04:03

user1290584


1 Answers

It's a self executing function:

!function(x){}(y)

x is the parameter of the function and y is the parameter you pass in the auto-call of that function.

! is just a visual guide that tells you at a glance that the function is self executing. Another common practice is to wrap it in parenthesis instead. (function(){}())

like image 104
elclanrs Avatar answered Mar 17 '26 04:03

elclanrs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!