js-object-clone icon indicating copy to clipboard operation
js-object-clone copied to clipboard

Include WeakMap shim by default.

Open jklmli opened this issue 10 years ago • 1 comments

https://github.com/Benvie/WeakMap provides a WeakMap implementation for most browsers that don't support it.

Including this with js-object-clone means circular references can be handled by default.

This is just a suggestion, I just manually add the shim myself in my wrapper for js-object-clone.

jklmli avatar Mar 11 '15 04:03 jklmli

From the WeakMap shim repo:

Under the hood, WeakMap uses Object.setProperty to create a unique property on each object that is added to a WeakMap, then the value of that property is used as the key to perform lookups into a regular JavaScript Object.

That means it's not suitable when copying objects. On the other side, I don't see why we couldn't use the shimmable Map. There's gonna be no memory leak if we clean and reuse it afterwards.

cshaa avatar Mar 12 '16 14:03 cshaa