Skip to content

Instantly share code, notes, and snippets.

Created November 11, 2013 04:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save anonymous/7407896 to your computer and use it in GitHub Desktop.
Save anonymous/7407896 to your computer and use it in GitHub Desktop.
Small, moderately scale-able library boilerplate using an immediately invoked object expression
!{
//convenience methods here for create and expose via this
create: function(options){
//constructor logic here
var created = Object.create(this.fn);
var args = [].slice.call(arguments);
this.plugins.forEach(function(plugin){
plugin.apply(created, args);
});
return created;
},
fn:{//prototype methods here
},
expose:function(NameSpace, window, document, plugins){
window[NameSpace] = this;//This can be tweaked for whatever
this.document = document;
this.plugins = plugins;
}
}.expose("LibraryNamespaceHere", window, document, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment