Skip to content

Instantly share code, notes, and snippets.

@wenbing
Created April 30, 2012 07:37
Show Gist options
  • Save wenbing/2556294 to your computer and use it in GitHub Desktop.
Save wenbing/2556294 to your computer and use it in GitHub Desktop.
walk in js
var walk = function(list, callback) {
var getCB = function(next) {
return function(o) {
callback(o, next)
};
},
handle = function() {
var item, cb, res = {};
if(list.length <= 0) {
return;
}
item = list.shift();
cb = getCB(handle);
res.data = item;
cb(res);
};
handle();
};
walk(['one', 'two', 'three'], function(o, next) {
console.log(o.data);
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment