Last active
December 10, 2015 02:19
-
-
Save hughfdjackson/4366781 to your computer and use it in GitHub Desktop.
Why void is better for iifes.
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
| // This is our first js file. We haven't put a trailing ; on the end | |
| var a = 3 | |
| alert(a) | |
| // this is our second file, which we've concated on to the end of the first file to HTTP requests | |
| void function(){ | |
| alert('hi') | |
| }() | |
| // because ASI doesn't think that `void` means you want to continue your expression, this works |
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
| // This is our first js file. We haven't put a trailing ; on the end | |
| var a = 3 | |
| alert(a) | |
| // this is our second file, which we've concated on to the end of the first file to HTTP requests | |
| (function(){ | |
| alert('hi') | |
| })() | |
| // because ASI doesn't insert in a ; when it thinks you want to continue your expression, it tries to *execute the return from alert* | |
| // and pass in the function in our second file. D'oh. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment