Skip to content

Instantly share code, notes, and snippets.

@mythmon
Created July 15, 2013 03:42
Show Gist options
  • Save mythmon/5997353 to your computer and use it in GitHub Desktop.
Save mythmon/5997353 to your computer and use it in GitHub Desktop.
function coolGraph(opts) {
// Since d3 doesn't like prototype style...
var me = {
foo: makeChainableGetterSetterWithDefault('foo'),
bar: makeChainableGetterSetterWithDefault('bar')
};
// Obviously you could do that in a loop if you have a lot of properties, and
// that function name is pretty gross, a better name might be `property`.
// Now that the object is set up, this will loop through everything in `opts`, and call the right setter on `me`.
var key;
for (key in opts) {
if (!opts.hasOwnProperty(key)) continue;
me[key](opts[key]);
}
// for d3's chaining.
return me;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment