gpt4 book ai didi

Javascript 定义对象属性和函数的新方法?

转载 作者:行者123 更新时间:2023-11-29 15:50:40 28 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
What is the purpose of wrapping whole Javascript files in anonymous functions like “(function(){ … })()”?

我多次偶然发现这种不寻常的编码方式,而且它似乎越来越流行。

(function (variable) {
// properties or methods go here

// some more stuff
})(variable)

我什至很难研究它,因为我什至不知道它的名字。我已经使用 jquery 使用它,但我仍然不知道它是如何使用的有效。

例子:

(function ($) {
...
// code to manipulate the dom
function init() {
.....
}

$(document).ready(function () {
init();
});
})(jQuery);

我只使用它是因为我正在更新其他开发人员编写的一些代码。

这样编码有什么好处吗?有什么地方可以让我阅读更多相关信息吗?如果有人理解我的问题,那么很高兴看到一些讨论这个问题的文章,或者您可能对如何制作自己的文章有一些见解。

谢谢

伊布

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