Created
August 25, 2014 09:13
-
-
Save namlook/ca831197abf2c61dc066 to your computer and use it in GitHub Desktop.
Plugin System
This file contains hidden or 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
// don't write this | |
var myLib = function(options) { | |
if (options.foo) doThis(); | |
if (options.bar) doSomeOtherStuff(); | |
if (options.baz) coverSomeWeirdEdgeCase(); | |
}; | |
// write this instead | |
var myLib = function(plugins) { | |
for (var name in plugins) { | |
var value = plugins[name]; | |
myLib.plugins[name](value); | |
}); | |
}; | |
myLib.plugins.baz = function() { | |
coverSomeWeirdEdgeCase(); | |
}; // etc... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment