Skip to content

Instantly share code, notes, and snippets.

@namlook
Created August 25, 2014 09:13
Show Gist options
  • Save namlook/ca831197abf2c61dc066 to your computer and use it in GitHub Desktop.
Save namlook/ca831197abf2c61dc066 to your computer and use it in GitHub Desktop.
Plugin System
// 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