Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created November 28, 2016 08:40
Show Gist options
  • Save andreasvirkus/9cb87002716625ee24130278e1aa675e to your computer and use it in GitHub Desktop.
Save andreasvirkus/9cb87002716625ee24130278e1aa675e to your computer and use it in GitHub Desktop.
/**
* 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