Last active
July 24, 2017 13:56
-
-
Save tekaratzas/bdf3e4619dc5297405658225a96b228a to your computer and use it in GitHub Desktop.
Anonymous Wrappers and Namespaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( | |
// evaluate the function in the parenthesis | |
function(){} | |
// return the evaluated function object | |
)() // call it immediately | |
// The same functionality can be done as follows; | |
!function(){}() | |
+function(){}() | |
(function(){}()); | |
// PRO TIP: | |
// if some jerk on your team does this. AKA overwrites the global variable "undefined" | |
console.log(typeof undefined === "undefined") // true | |
var undefined = 123; | |
console.log(typeof undefined === "undefined") // this is false! undefined is overwritten and replaced by the number 123 | |
// you can avoid a catastrophe by using an anonymous wrapper. | |
(function(undefined){console.log(undefined);})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment