I'm a self-taught dev focused on websites and Python development.
My friends call me the "Data Genie".
When I get bored, I find tech to read about, write about and build things with.
Thanks for sharing. I hadn't heard of WeakMap.
I think your two get and set functions, in both cases, add unnecessary complexity and the built methods can make it clearer.
This below is much easier to follow for me and avoids relying on functions to have side effects on a global object.
I can see how putting use of .$dataKey in a function can help in larger application but in the first case you could just set and get directly without the functions.
Also I think it should be mentioned that you can't use this .get on any element to find its data unless you first make a map and send data on the map.
Thanks for sharing. I hadn't heard of WeakMap.
I think your two get and set functions, in both cases, add unnecessary complexity and the built methods can make it clearer.
This below is much easier to follow for me and avoids relying on functions to have side effects on a global object.
I can see how putting use of
.$dataKey
in a function can help in larger application but in the first case you could just set and get directly without the functions.Also I think it should be mentioned that you can't use this .get on any element to find its data unless you first make a map and send data on the map.
That's good too. The main thing is the
WeakMap
after all, you can use it in any way you like to 😀