Ticker.js

var extend = require("extend"),
    EventEmitter = require("events").EventEmitter;

var Ticker = function(interval){
  this.interval = interval;
};

Ticker.prototype = {
  "start": function(){
    var _this = this;
    setInterval(function(){
      _this.tick();
    }, this.interval);
  },
  "tick": function(){
    this.emit("tick");
  }
};

extend(Ticker.prototype, EventEmitter.prototype);

module.exports = Ticker;

main.js

var Ticker = require("./Ticker");

var ticker = new Ticker(1000);
var f = false;

ticker.on("tick", function(){
  document.body.innerHTML = (f=!f)?"tick":"tack";
});

ticker.start();

Browserify !

$ npm install browserify
$ browserify main.js

かくて