2 ms·
This is very useful and definitely something I am glad to see added to the language, previous solutions to this problem weren’t particularly efficient. I am co
by peanut_worm 5y ago
This is very useful and definitely something I am glad to see added to the language, previous solutions to this problem weren’t particularly efficient.
I am confused why they made it a global function though rather than a static method like object.assign though
also
> Functions: If your object contains functions, they will be quiety discarded.
that is a bit of a let down
- aliswe 5y agoi believe thats for the hack, stringifying then parsing the object.
- peanut_worm 5y agoOops I can’t read
- electroly 5y agoI think it's true for both -- they mention this both under the "Deep copies" section where it's talking about JSON.parse(JSON.stringify()), and also under "Structured cloning" > "Features and limitations" where it's talking about the new function. The line GP quoted is from the section where it's talking about structured cloning.
- olliej 5y agoSerializing functions is an exciting footgun of pain due to capturing/closures. Sure there are plenty of places where you could serialize easily, it’s super easy to become nonserializable and you end up in a position where sometime a function serializes, and sometimes it fails. Then there are semantic issues in later execution as a lot of primitive operations are defined in terms of the host global object, etc. So the safest option is to not support serialization.