Skip to content

Instantly share code, notes, and snippets.

@jaw187
Created January 18, 2016 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaw187/74dcabbd22abb2bdd64b to your computer and use it in GitHub Desktop.
Save jaw187/74dcabbd22abb2bdd64b to your computer and use it in GitHub Desktop.
Node Challenge, make this work by changing use
var Instance = function (options) {
this.options = options;
};
Instance.prototype.use = function (fn) {
var self = this;
process.nextTick(() => {
fn.call(self, self.options);
})
return this;
};
function foo (options) {
console.assert(options.foo.x === 1);
setImmediate(() => {
this.options.bar.y = 3;
})
}
function bar (options) {
console.assert(options.bar.y === 3, 'bar options invalid: ' + options.bar.y);
}
var instance = new Instance({ foo: { x: 1 }, bar: { x: 2 } })
instance.use(foo).use(bar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment