Created
May 12, 2014 02:06
-
-
Save gasolin/c457f0ed377d0f19a644 to your computer and use it in GitHub Desktop.
immediately-invoked function expressions(IIFE) http://tech.myemma.com/iifes-javascript-control-variable-scope/
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
| // Take control of your globals | |
| //basic | |
| (function () { | |
| // your code here | |
| })(); | |
| // pass param in | |
| (function ($) { | |
| $(document).ready(function () { | |
| // my code | |
| }); | |
| })(jQuery); | |
| // expose param out | |
| var obj = (function () { | |
| return { | |
| methodA: ... | |
| } | |
| })(); | |
| obj.methodA(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment