Last active
August 29, 2015 14:24
-
-
Save benaston/a3dc94b7cd1d00f94fdd to your computer and use it in GitHub Desktop.
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
var need = require('niid').need; | |
var mix = require('mixx').mix; | |
var defaultOptions = Object.freeze({ foo: undefined, | |
bar: undefined, | |
bam: null, | |
baz: null }); | |
function MyThing(options) { | |
need(options, 'foo', 'bar'); // `foo` and `bar` are required. | |
options = mix({}, defaultOptions, options); | |
mix(this, options); | |
} | |
// -- or, in fewer lines -- | |
function MyThing(options) { | |
need(options = mix({}, defaultOptions, options), 'foo', 'bar'); // `foo` and `bar` are required. | |
mix(this, options); | |
} | |
/** | |
* This results in an object with own-properties | |
* `foo`, `bar`, `bam` and `baz`, with the supplied | |
* values overriding the defaults. | |
*/ | |
var myThing = new MyThing({ foo: 'foo', bar: 'bar' }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is niid: https://github.com/benaston/niid/blob/master/src/niid.js
This is mixx: https://github.com/benaston/mixx/blob/master/src/mix.js