Created
July 16, 2013 19:29
-
-
Save maryrosecook/6011841 to your computer and use it in GitHub Desktop.
Go wild
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
var applyFn = function(node, fn) { | |
var applied = fn(node); | |
return applied === undefined ? node : applied; | |
}; | |
var macro = function(key, val) { | |
if (key.firstBit === repeatChild) { | |
repeatChild(key, val) | |
} | |
}; | |
var traverse = function(obj, keyFn, valFn) { | |
if (isString(obj)) { | |
return obj; | |
} | |
var newObj = {}; | |
for (var key in obj) { | |
var newKey = applyFn(key, fn); | |
var newVal = simple(newKey) ? | |
traverse(applyFn(obj[key], fn)) : | |
macro(key, obj[key]); | |
newObj[newKey] = newVal; | |
} | |
return newObj; | |
}; | |
var jsonGenerator = {}; | |
var generatedJson = traverse(jsonGenerator, function(x) { | |
return x; | |
}); | |
var jsonGenerator = { {}: { b:{} } }; | |
var generatedJson = traverse(jsonGenerator, function(x) { | |
return x; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment