Created
June 20, 2013 17:35
-
-
Save m1el/5824846 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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