Last active
August 29, 2015 14:07
-
-
Save mygoare/6dac8faf39e7e4dadbba to your computer and use it in GitHub Desktop.
Nodejs events listen and emit
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
// Nodejs event listen and emit | |
// 不光nodejs, Javascript 本身就有 eventEmitter | |
var events = require('events'); | |
var eventEmitter = new events.EventEmitter(); | |
var ringBell = function() | |
{ | |
console.log('ring ring ring'); | |
}; | |
eventEmitter.on('doorOpen', ringBell); | |
eventEmitter.emit('doorOpen'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment