javascript - Does JSON.stringify() always ignore methods when parsing objects? - Stack Overflow

I found the following in the Mozilla-documentation:If undefined, a function, or an XML value is encount

I found the following in the Mozilla-documentation:

If undefined, a function, or an XML value is encountered during conversion it is either omitted (when it is found in an object) or censored to null (when it is found in an array).

My question is: Do all modern browsers behave in this way? Can I rely on stringify() to ignore my object methods?

I found the following in the Mozilla-documentation:

If undefined, a function, or an XML value is encountered during conversion it is either omitted (when it is found in an object) or censored to null (when it is found in an array).

My question is: Do all modern browsers behave in this way? Can I rely on stringify() to ignore my object methods?

Share asked Oct 13, 2012 at 4:42 Konstantin SchubertKonstantin Schubert 3,3562 gold badges35 silver badges47 bronze badges 1
  • Firefox offers a propriatary method .toSource() for all of its objects. While I'd not use it for anything more than testing and debugging, it can be amazingly useful. – Jeremy J Starcher Commented Oct 13, 2012 at 7:35
Add a ment  | 

2 Answers 2

Reset to default 8

The plete algorithm for JSON.stringify can be found in the specification: https://es5.github.io/x15.12.html#x15.12.3.

Basically, for every value that is not an object, null, a boolean, a number or a string, the serialisation function returns undefined and undefined values are not rendered.

That does not necessarily guarantee that every browser implements it this way, but the only browser getting out of line is normally IE. Every other browser is very close to the specification.

Yes.

Except for IE7, which doesn't implement it, and IE8, which requires document to be in standards mode, stringify works well across browsers

See: http://caniuse./#search=json

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742405863a4437833.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信