4

I file in a project contains the following code:

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

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

}
})(window);
//end of the file
  • What does this structure mean?
  • What is this line for ((window) => {}(window); ?
  • What does constructor()mean ?

My English a little poor,hope I make the question clear.:-)

scott_lotus
  • 3,171
  • 22
  • 51
  • 69
Broven
  • 63
  • 7

2 Answers2

1

This is Module Pattern written on ES6. It allows you group your variables in the same scope and isolate them from other "modules".

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

You can find more detailed answer about it here.

constructor function allows you initialize your class instance.

Community
  • 1
  • 1
LazyCat01
  • 957
  • 7
  • 23