javascript - Why can Errors not be stringified? -
this question has answer here:
why can errors not stringified?
json.stringify(new referenceerror('foo')); // {}
when example, date more useful:
json.stringify(new date()); // "2015-04-01t10:23:24.749z"
javascript error
objects not enumerable. can verify easily:
new error('test').propertyisenumerable('message'); // -> false
you can define own tojson
function on error object:
object.defineproperty(error.prototype, 'tojson', { value: function () { return {value: "test"}; }, configurable: true }); json.stringify(new error()); -> "{value: "test"}"
Comments
Post a Comment