Skip to content

Instantly share code, notes, and snippets.

@jcblw
Created July 7, 2015 03:55
Show Gist options
  • Save jcblw/7198877f99d35aeaead1 to your computer and use it in GitHub Desktop.
Save jcblw/7198877f99d35aeaead1 to your computer and use it in GitHub Desktop.
stringify an object with functions
module.exports = function stringifyObject(obj) {
var
ret = '{',
keys = [],
_key = '';
for(var key in obj) {
_key += '\'' + key + '\' : ';
if (typeof obj[key] === 'object') {
_key += stringifyObject(obj[key]);
} else if (obj[key]) {
_key += obj[key].toString();
} else {
_key += 'undefined';
}
keys.push(_key);
_key = '';
}
ret += keys.join(',');
ret += '}';
return ret;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment