JS函数定义:最后括号的含义 [英] JS function definition : meaning of the last parentheses

查看:298
本文介绍了JS函数定义:最后括号的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:



这是什么意思? (function(x,y)){...}){a,b);在JavaScript中


有时我会看到像这些例子定义的函数:

 (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)作为参数。


Possible Duplicate:
What is the purpose of a self executing function in javascript?
What does this mean? (function (x,y)){…}){a,b); in JavaScript

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?

解决方案

meaning of the last brakets

(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函数定义:最后括号的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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