Skip to content

Instantly share code, notes, and snippets.

@m1el
Created June 20, 2013 17:35
Show Gist options
  • Save m1el/5824846 to your computer and use it in GitHub Desktop.
Save m1el/5824846 to your computer and use it in GitHub Desktop.
function deepMap(obj, fn, that) {
var stack = {0: {obj: obj}},
sp = 0,
ss = 1,
scope, keys, i, val;
while ((scope = stack[sp++])) {
keys = Object.keys(scope.obj);
for (i = 0; i < keys.length; i++) {
val = scope.obj[keys[i]];
fn.call(that, val, keys[i]);
if (val && Object(val) === val) {
stack[ss++] = {obj: val};
}
}
delete stack[sp - 1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment