Reputation: 28324
I have this code in a code base I am looking at and I am trying to figure out whats going on.
I understand that MyDefinedVariable_1 is getting the instance of some file.js. However I want to know
1- why is MyDefinedVariable_1 referenced at the end of MyDefinedVariable_2 like })(MyDefinedVariable_1). What purpose that serve?
2- What is _super? It seems to me some query thing but not sure
var MyDefinedVariable_1 = require(‘somefile.js);
var MyDefinedVariable_2 = (function (_super) {
..……….
…………
})(MyDefinedVariable_1);
thanks
Upvotes: 0
Views: 33
Reputation: 51062
MyDefinedVariable_2
is being set to the results of defining and then calling a function. That function takes a parameter called _super
. When the function is being called, MyDefinedVariable_1
is being passed in as the function parameter (so within the function, wherever it says _super
the value used will be whatever is assigned to MyDefinedVariable_1
).
Here's a simpler example:
var a = 1;
var b = (function(myParam){
return myParam + 4;
})(a);
After running this, b
will be 5. When defining b
, we called the function that adds 4 to whatever was passed in (myParam
), and what we passed in was a
. And a
was assigned 1. So b
will be 5.
Upvotes: 1