Created
January 18, 2016 15:16
-
-
Save jaw187/74dcabbd22abb2bdd64b to your computer and use it in GitHub Desktop.
Node Challenge, make this work by changing use
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 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