Skip to content

Instantly share code, notes, and snippets.

@jtenner
Forked from anonymous/gist:7407896
Last active December 28, 2015 00:59
Show Gist options
  • Save jtenner/7416928 to your computer and use it in GitHub Desktop.
Save jtenner/7416928 to your computer and use it in GitHub Desktop.
!{
//Typical API functions should go here
//func : function(){}....
//func2 : function(options){...}
//Object creation methods...
//convenience methods here for create and expose via this
createObject: 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, target, plugins){//initialization code.
target[NameSpace] = this;//target can be the window (exposed) or some other object
this.plugins = plugins;
delete this.expose; //remove the reference to expose
}
}.expose("LibraryNamespaceHere", {}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment