serialize-javascript icon indicating copy to clipboard operation
serialize-javascript copied to clipboard

Support custome object

Open harvey-woo opened this issue 5 years ago • 0 comments

Add support for serialization and deserialization of custom objects via Object.assign and Object.create For example:

class A {
    a = 1
}
serialize(A, { classes: { A } })

get

const serialized = "(function(args) {var k = args[0].classes;return args[0].assign(Object.create(k.A.prototype), { a: 1 })})(arguments)"
function unserialize() {
    return eval(serialized)
}
unserialize({ classes: {A: function() {}}, assign: Object.assign })

harvey-woo avatar Apr 28 '19 07:04 harvey-woo