Last active
January 6, 2017 03:36
-
-
Save wowiwo1/31ea59dc95325b6af2af07d997c9347c 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 http = require("http") | |
// var util = require("util") | |
var EventEmitter = require("events").EventEmitter | |
//============ version 1 ============== | |
var Ticker = function () { | |
setInterval(()=>{ | |
console.log("tick") | |
this.emit("tick") | |
}, 1000) | |
} | |
EventEmitter.call(Ticker.prototype) | |
Object.setPrototypeOf(Ticker.prototype, EventEmitter.prototype) | |
// util.inherits(Tick, EventEmitter) // 동일한 표현 | |
var ticker = new Ticker() | |
ticker.on("tick", ()=>{ | |
console.log("tock") | |
}) | |
//============ version 2 ============== | |
var ticker = Object.create(new EventEmitter()) | |
setInterval(()=>{ | |
console.log("tick") | |
ticker.emit("tick") | |
}, 1000) | |
ticker.on("tick", ()=>{ | |
console.log("tock") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment