gpt4 book ai didi

javascript - 自执行匿名函数中 (fn...)() 括号的用途? [JavaScript]

转载 作者:行者123 更新时间:2023-11-30 13:37:54 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Location of parenthesis for auto-executing anonymous JavaScript functions?

问题是重复的 Location of parenthesis for auto-executing anonymous JavaScript functions?What do parentheses surrounding a object/function/class declaration mean?

真的很好奇,这段代码中括号的用途是什么:

(function() {})();

这看起来我可以很容易地写成:

var x=function(){};
(x)();

使用 jQuery 插件,我们会做类似的事情......

(function($) {})(jQuery);

括号是怎么回事?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com