diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-11-28 20:34:32 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-11-28 20:34:32 -0800 |
commit | 7b6798ecf48622d5c9fe9b20a5950bd5c3f13bb7 (patch) | |
tree | 7baa94e3bc1acb13a08900a29915e5a55cf8bc08 /src/utility.js | |
parent | 2b46a65a8d91e0721a7cdd7f91e4899e07831eaa (diff) |
support for nested objects in library objects, including functions
Diffstat (limited to 'src/utility.js')
-rw-r--r-- | src/utility.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/utility.js b/src/utility.js index 737d515a..e49776d8 100644 --- a/src/utility.js +++ b/src/utility.js @@ -284,3 +284,13 @@ function jsonCompare(x, y) { return JSON.stringify(x) == JSON.stringify(y); } +function stringifyWithFunctions(obj) { + if (typeof obj === 'function') return obj.toString(); + if (obj === null || typeof obj !== 'object') return JSON.stringify(obj); + if (isArray(obj)) { + return '[' + obj.map(stringifyWithFunctions).join(',') + ']'; + } else { + return '{' + keys(obj).map(function(key) { return key + ':' + stringifyWithFunctions(obj[key]) }).join(',') + '}'; + } +} + |