Skip to content

Instantly share code, notes, and snippets.

@jtenner
Created November 8, 2013 17:51
Show Gist options
  • Save jtenner/7374869 to your computer and use it in GitHub Desktop.
Save jtenner/7374869 to your computer and use it in GitHub Desktop.
The innner workings of the plugin architecture
plugins = [];
//inside of NovelScript.js
NovelScript["plugin"] = function(func){
plugins.push(func);
}
//inside of the NovelScript function constructor
plugins.forEach(function(plugin){
plugin(self, options);
});
//plugin code here
!function(NovelScript){
NovelScript.plugin(function(self, options){
//do something to the current NovelScript object using the options provided
});
//NovelScript.prototype is accessable here
}(NovelScript);
//constructor performs construction and then calls plugins.forEach
var x = new NovelScript(options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment