-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
I've modified your code to stringify objects with prototype. Here is my version:
exports.stringify = function(obj) {
//Original Stringify
var partialStringify = function (obj) {
return JSON.stringify(obj, function (key, value) {
if (value instanceof Function || typeof value == 'function') {
return value.toString();
}
if (value instanceof RegExp) {
return '_PxEgEr_' + value;
}
return value;
});
};
//Calculate normal return
var normal = partialStringify(obj);
//Stringify prototype with recursively
var proto = obj.__proto__? this.stringify(obj.__proto__): "";
//If prototype was not {} empty
if( proto.length > 2 ) {
//Slide the brackets and put a coma in between
return normal.slice(0,-1) + ', ' + proto.slice(1);
}
return normal;
};
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels