问题描述
有时我会看到像这些例子定义的函数:
(function(){
....
})();
(function(param){
....
})(JQuery);
$ b $(函数(聊天,朋友){
....
})(chat,chat.module(friend);
经过一些网络研究后,我没有找到任何有关最后括号信息含义的信息。
是否有人解释如何使用它?或者只是指出一个解释含义的网络链接? blockquote>
最后一个脚架的含义
(function() {
....
})();
<$> ()最终导致函数内部的代码立即执行。
(function(param){
....
})(JQuery);
最后的(JQuery)会导致函数中的代码立即执行,并传递 JQuery 作为参数。
(function(chat,Friend){
....
})(chat,chat.module(friend));
(chat,chat.module(friend))最后code>导致函数中的代码立即执行,并传递 chat 和 chat.module(friend)作为参数。
I see sometimes functions defined like these examples :
(function() { .... })(); (function(param) { .... })(JQuery); (function(chat, Friend) { .... })(chat, chat.module("friend");
After some web researches, I didn't find any information about the meaning of the last parentheses information.
Is there someone to explain how to use it? Or simply point a web link explaining the meaning?
(function() { .... })();
The () in the end causes the code inside the function to be executed immediately.
(function(param) { .... })(JQuery);
The (JQuery) in the end causes the code inside the function to be executed immediately, passing JQuery as a parameter to it.
(function(chat, Friend) { .... })(chat, chat.module("friend"));
The (chat, chat.module("friend")) in the end causes the code inside the function to be executed immediately, passing chat and chat.module("friend") as parameters to it.
这篇关于JS函数定义:最后括号的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!