你如何在 JavaScript 中解释这种结构? [英] How do you explain this structure in JavaScript?
本文介绍了你如何在 JavaScript 中解释这种结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(function()
{
//codehere
}
)();
这种语法有什么特别之处?()() 是做什么的;暗示?
What is special about this kind of syntax? What does ()(); imply?
推荐答案
The 创建一个匿名函数,闭包和所有,并且 final () 告诉它自己执行.
The creates an anonymous function, closure and all, and the final () tells it to execute itself.
基本相同:
function name (){...}
name();
所以基本上这段代码没有什么特别之处,它只是创建一个方法并调用它而无需命名的快捷方式".
So basically there is nothing special about this code, it just a 'shortcut' to creating a method and invoking it without having to name it.
这也意味着函数是一次性的,或者是对象的内部函数,当你需要闭包的特性时最有用.
This also implies that the function is a one off, or an internal function on an object, and is most useful when you need to the features of a closure.
这篇关于你如何在 JavaScript 中解释这种结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文