UNPKG

emitter-b

Version:

An enhanced EventEmitter with extra methods for detecting whether an event has any handlers or not for efficient event handler attachment.

33 lines (30 loc) 816 B
// you define the functions up front, and when you call the return value, it passes the arguments you call it with to the functions in sequence // returns a function that, each time its called, calls the next function in the list with the passed argument // example: /* var sequenceX = testUtils.seq( function(x) { t.ok(x === 'a') }, function(x) { t.ok(x === 'b') }, function(x) { t.ok(x === 'c') }) var obj = {a:1,b:2,c:3} for(var x in obj) { sequenceX(x) } */ exports.seq = function (/*functions*/) { var n=-1 var fns = arguments return function() { n++ if(n>=fns.length) throw new Error("Unexpected call "+n+". Arguments: "+Array.prototype.slice.call(arguments)) // else fns[n].apply(this,arguments) } }