如何将整个 Javascript 对象字符串化,包括 __proto__ 属性? [英] How to stringify a whole Javascript Object including __proto__ properties?

查看:46
本文介绍了如何将整个 Javascript 对象字符串化,包括 __proto__ 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是重复的,我很抱歉,到目前为止我找不到相同的问题.

I am sorry if this is a duplicate, so far I couldn't find the same question.

我的 __proto__ 成员中有一个带有各种方法的对象.让我们调用这个对象的类型myObjectType.

I have an Object with various methods in my __proto__ member. Let's call the type of this object myObjectType.

稍后我必须做一个JSON.stringify(myObjectType).问题是,当我从之前获得的 JSON 字符串构建我的对象时,我的对象类型是普通的 Object,我失去了我拥有的所有方法.

Later on I have to do a JSON.stringify(myObjectType). The problem is that then when I build my object from the previous obtained JSON string the type of my Object is plain Object, I lost all the methods I had.

有人明白为什么吗?

推荐答案

没有将函数合并到 JSON 数据的标准化方法.你可以自己做一些事情—也就是说,编写您自己的 JSON 序列化程序,根据某些约定合并函数 —但是使用直接的标准 JSON,您可以获得数字、字符串、布尔值和 null,当然还有具有命名属性和数组的对象.没有函数,只有数据.

There's no standardized way of incorporating functions into JSON data. You can do something yourself — that is, write your own JSON serializer that incorporates functions according to some convention — but with straight standard JSON you get numbers, strings, booleans, and null, plus of course objects with named properties and arrays. No functions, just data.

这篇关于如何将整个 Javascript 对象字符串化,包括 __proto__ 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆