Created
November 28, 2016 08:40
-
-
Save andreasvirkus/9cb87002716625ee24130278e1aa675e to your computer and use it in GitHub Desktop.
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
/** | |
* An export pattern for global objects | |
* (to avoid pollution) | |
*/ | |
// File A | |
var foo = (function (that) { | |
that.bar = 1; | |
return that; | |
}(foo || {})); | |
// File B | |
var foo = (function (that) { | |
that.baz = 2; | |
return that; | |
}(foo || {})); | |
// Result is a single object | |
foo = { | |
bar: 1, | |
baz: 2 | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment