[英]Why would I ever use Array.toSource?
Apparently there's a non-standard method of Array
, toSource
. 显然,有一个非标准的
Array
方法toSource
。 As per the example.. 按照示例。
var alpha = new Array('a', 'b', 'c'); alpha.toSource(); // ['a', 'b', 'c']
.. it seems to do the same thing as JSON.stringify
: ..它似乎和
JSON.stringify
做同样的事情:
var alpha = new Array('a', 'b', 'c');
JSON.stringify(alpha);
So why would I want to use Array.toSource
? 那我为什么要使用
Array.toSource
?
You don't. 你不知道
toSource()
is a holdover from the Netscape days and has been obsolete for ages. toSource()
是Netscape时代的 toSource()
,并且已经过时了。 It was, however, the only built-in way to convert an object to its source representation before what we now know as JSON, let alone the respective de/serialization APIs, ever came into existence. 但是,它是将对象转换为其源表示形式的唯一内置方法,而现在我们还不知道相应的反/序列化API。
toSource()函数仅将数组转换为字符串格式,而JSON.stringify()能够将数组以及javascript对象转换为字符串格式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.