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 ?
Stringify a JavaScript ObjectUse the JavaScript function JSON.stringify() to convert it into a string. const myJSON = JSON.stringify(obj); The result will be a string following the JSON notation.
__proto__ is a way to inherit properties from an object in JavaScript. __proto__ a property of Object. prototype is an accessor property that exposes the [[Prototype]] of the object through which it is accessed. POSTly is a web-based API tool that allows for fast testing of your APIs (REST, GraphQL).
JSON. stringify() will encode values that JSON supports. Objects with values that can be objects, arrays, strings, numbers and booleans. Anything else will be ignored or throw errors.
The prototype property is set to function when it is declared. All the functions have a prototype property. proto property that is set to an object when it is created using a new keyword. All objects behavior newly created have proto properties.
search google for javascript object serialization.
GSerializer library
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With