My JavaScript book is out! Don't miss the opportunity to upgrade your beginner or average dev skills.

Friday, April 17, 2015

A WeakMap Polyfill in 20 lines of code

In case you missed my yesterday post, we finally have a widely compatible cross engine poly for Object.getOwnPropertySymbols(obj).
What I've also tried to epxlain in the very same post, is that Symbol unlocks new patterns for "secret" properties definition, and the following little WeakMap is just one example on how symbols can be used to relate data we don't want to show in other common ways.

OK, maybe is not the most perfect polyfill we can have ... but you've got the idea on what could be done through Symbol variables ;-)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.