jQuery和Twitter Bootstrap功能说明 [英] jQuery and Twitter Bootstrap function explanation
问题描述
如果您看到所有文档中存在的twitter引导程序application.js文件,您会注意到以下代码:
!function($){
...
}(window.jQuery);
有人可以解释为什么代码的第一行是这种情况吗?
感谢
这是一个自我执行的函数:
!function(x){}(y)
x
是函数的参数, y
是您在自动呼叫该功能。
!
只是一个视觉指南,一目了然地告诉你该函数是自动执行的。另一种常见做法是将其包装在括号中。 (function(){}())
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
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(){}())
这篇关于jQuery和Twitter Bootstrap功能说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!