Created
July 15, 2013 03:42
-
-
Save mythmon/5997353 to your computer and use it in GitHub Desktop.
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
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