问题描述
我在 Mozilla文档:
我的问题是:所有现代浏览器都以这种方式运行吗?我可以依靠stringify()忽略我的对象方法吗?
My question is: Do all modern browsers behave in this way? Can I rely on stringify() to ignore my object methods?
推荐答案
可以在规范中找到JSON.stringify
的完整算法: http://es5.github.com/#x15.12.3 .
The complete algorithm for JSON.stringify
can be found in the specification: http://es5.github.com/#x15.12.3.
基本上,对于不是对象,null
,布尔值,数字或字符串的每个值,序列化函数都会返回undefined
,并且不会呈现undefined
值.
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.
并不一定保证每个浏览器都以这种方式实现它,但是唯一脱离常规的浏览器通常是IE.其他所有浏览器都非常符合规范.
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.
这篇关于解析对象时,JSON.stringify()是否总是忽略方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!