While looking via some modules sources for node.js I have found one having the following construction:
;(function(global){
var a = // some definitions
.. // code
})(typeof window === "object" ? window : this);
So what is the meaning to write:
The semicolon is a safety measure for minifications (elaborated on here).
The second part of your question: (typeof window === "object" ? window : this) is checking whether the code runs in a browser. If window is actually defined, then we conclude it runs in a browser, if not it runs in node. Then we pass this environment (node.js or window) as a variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With