I need to use localStorage to store some Ember objects. I notice that Ember objects have properties with names like __ember1334992182483
. When I call JSON.stringify()
on Ember objects, these __ember*
properties __ember*
not serialized. Why is this? I am not saying that I want to serialize these properties. I'm just curious what exactly they are and how they are implemented so that they are not serialized.
I am using cycle.js ( https://github.com/douglascrockford/JSON-js/blob/master/cycle.js ) to encode my data structures containing duplicate links into a string that can be used to restore the original data structures. He allows you to do this:
a = {a:1} b = {b:1} c = [[a, b], [b, a]] foo = JSON.stringify(JSON.decycle(c)) // "[[{'a':1},{'b':1}],[{'$ref':'$[0][1]'},{'$ref':'$[0][0]'}]]" JSON.retrocycle(JSON.parse(foo)) // reconstruct c
For Ember objects, I can do the same, but I also need to pass the deserialized objects to Ember.Object.create()
, because they are deserialized like regular JavaScript objects.
Is this the best way to serialize / deserialize Ember objects? Is there a recommended technique for this?
source share