简体   繁体   中英

Why would I ever use Array.toSource?

Apparently there's a non-standard method of 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 :

var alpha = new Array('a', 'b', 'c');

JSON.stringify(alpha);

So why would I want to use Array.toSource ?

You don't. toSource() is a holdover from the Netscape days and has been obsolete for ages. 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.

toSource()函数仅将数组转换为字符串格式,而JSON.stringify()能够将数组以及javascript对象转换为字符串格式

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM