最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

prototype - How to stringify a whole Javascript Object including __proto__ properties? - Stack Overflow

programmeradmin2浏览0评论

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

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

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.

Does any one see why ?

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

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

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.

Does any one see why ?

Share Improve this question asked Apr 26, 2011 at 12:51 SpredzySpredzy 5,17413 gold badges56 silver badges70 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

search google for javascript object serialization.

GSerializer library

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.

I'd highly remend Douglas Crockford's libraries:

https://github./douglascrockford/JSON-js

发布评论

评论列表(0)

  1. 暂无评论