jQuery and Twitter Bootstrap function explanation

后端 未结 3 1775
無奈伤痛
無奈伤痛 2021-01-07 01:55

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

!function( $ ) {
    ...
         


        
3条回答
  •  借酒劲吻你
    2021-01-07 02:14

    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(){}())

提交回复
热议问题