Created
November 8, 2013 17:51
-
-
Save jtenner/7374869 to your computer and use it in GitHub Desktop.
The innner workings of the plugin architecture
This file contains 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
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