本文介绍了以下JavaScript构造是否称为Closure?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(function() {

  //do stuff

})();

编辑:我原本认为这个结构被称为闭包 - 而不是它导致的结果(可能)在闭包中 - 如果捕获变量。

I originally thought this construct was called a closure - not that the effect that it caused results (potentially) in a closure - if variables are captured.

这与封闭本身的行为没有任何关系 - 我完全理解这一点并不是被问到的。

This is in no way to do with the behaviour of closures themselves - this I understand fully and was not what was being asked.

推荐答案

这是一个匿名函数(或者更确切地说是)立即执行。

It is an anonymous function (or more accurately a scoped anonymous function) that gets executed immediately.

使用一个是在其中声明的任何变量和函数都限定为该函数因此隐藏在任何全局上下文中(因此您获得封装和信息隐藏)。

The use of one is that any variables and functions that are declared in it are scoped to that function and are therefore hidden from any global context (so you gain encapsulation and information hiding).

这篇关于以下JavaScript构造是否称为Closure?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 21:33