jQuery和Twitter Bootstrap功能说明 [英] jQuery and Twitter Bootstrap function explanation

查看:155
本文介绍了jQuery和Twitter Bootstrap功能说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您看到所有文档中存在的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆