A little more detail?
trusktr opened this issue · 4 comments
So, can we in theory encode an instance of a class then decode it multiple times in order to create new instances instead of using the new
keyword over and over?
class Cat extends Animal { ... }
let geneSample = encode(new Cat())
// make clones
let cat1 = decode(geneSample)
let cat2 = decode(geneSample)
let geneSample2 = encode(new Cat({some: 'characteristic'}))
// make more clones
let cat3 = decode(geneSample2)
let cat4 = decode(geneSample2)
?
I was wondering, because of the example in the README:
console.log(decode(encode(a)) instanceof MyType)
What if an instance to the MyType
constructor isn't available in the destination where the encoded value is sent? Does it encode the full prototype chain, so when decoded the new object is the same as one that would have been created with new
?
What if an instance to the MyType constructor isn't available in the destination where the encoded value is sent?
No, a type needs to be registered on both side.
Does it encode the full prototype chain, so when decoded the new object is the same as one that would have been created with new?
No, the prototype chain is not encoded. The object will be the same as if it has been created with the local prototype.