フロントエンドエンジニア芸人もりたけんじのJavaScript【JavaScript】JavaScript中級者の為の練習問題集261問(脱初心者へ)2016/09/10更新

【JavaScript】去り際が格好いいECMAScript2015「WeakMap」のイケメンさがわかる記事

【JavaScript】去り際が格好いいECMAScript2015「WeakMap」のイケメンさがわかる記事

Resources
「What Are Weakmaps In ES6?」
ES6 Everyday: WeakMaps

One of the biggest caveats (by design) is the lack of size, followed by the inability to use strings as key names and also the inability to iterate over a WeakMap.

・なぜweakか。ガーベージコレクションの対象なので。
・ユースケースはDOMelementでdataとして扱う時。DOMに対してデータを格納でき、DOMが削除、存在していないならweakMapの内部の参照はガーベージコレクションの対象になる。明示的な要請なしにclean upしてくれる。(Jqueryのようにいつまでも参照を残さないことを意味する)
・keynameとしてstring型が使えない
・keyはnullじゃないObject、keyはany
・iteratableではない

///////////////
This allows us to treat DOM objects as the objects they are complete with their own states and data independent of everything else within your application that will be garbage collected if they are removed.
///////////////

JS Bin on jsbin.com