Created
June 19, 2016 13:12
-
-
Save j8/4e96470619c1d842913234060499aefe to your computer and use it in GitHub Desktop.
#Node.js interview questions
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
# | |
# Node.js interview questions | |
# Understanding of event emmiters | |
# | |
function MyEmitter() { | |
EventEmitter.call(this); | |
} | |
util.inherits(MyEmitter, EventEmitter); | |
MyEmitter.prototype.doStuff = function doStuff() { | |
console.log('before') | |
emitter.emit('fire') | |
console.log('after')} | |
}; | |
var me = new MyEmitter(); | |
me.on('fire', function() { | |
console.log('emit fired'); | |
}); | |
me.doStuff(); | |
// Output: | |
// before | |
// emit fired | |
// after |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment