【问题标题】:What is ((window) => { ...})(window); meaning什么是 ((window) => { ...})(window);意义
【发布时间】:2016-10-12 19:39:34
【问题描述】:

我在一个项目中的文件包含以下代码:

 //begin of the file
 ((window) => {
    'use strict';
class View extends GSM.EventEmitter {

    constructor() {
        super();
//some function here

}
})(window);
//end of the file
  • 这个结构是什么意思?
  • ((window) => {}(window); 的这一行是什么?
  • constructor()是什么意思?

我的英语有点差,希望我把问题说清楚。:-)

【问题讨论】:

  • 我的回答有用吗?还是您需要更多信息???

标签: javascript


【解决方案1】:

这是用 ES6 编写的模块模式。它允许您将变量分组在同一范围内,并将它们与其他“模块”隔离开来。

(function(/* your deps */){
  //your code
  var privateVariable;
}(/* your dependencies */))

你可以找到更详细的答案here

constructor 函数允许你初始化你的类实例。

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多