2 ## WeakMap collection as specified in ECMAScript6
4 _Roughly inspired by Mark Miller's and Kris Kowal's [WeakMap implementation](https://github.com/drses/weak-map)_.
7 - Assumes compliant ES5 environment (no weird ES3 workarounds or hacks)
8 - Well modularized CJS style
9 - Based on one solution.
13 - Will fail on non extensible objects provided as keys
14 - While `clear` method is provided, it's not perfectly spec compliant. If some objects were saved as _values_, they need to be removed via `delete`. Otherwise they'll remain infinitely attached to _key_ object (that means, they'll be free for GC only if _key_ object was collected as well).
18 $ npm install es6-weak-map
20 To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/)
24 If you want to make sure your environment implements `WeakMap`, do:
27 require('es6-weak-map/implement');
30 If you'd like to use native version when it exists and fallback to polyfill if it doesn't, but without implementing `WeakMap` on global scope, do:
33 var WeakMap = require('es6-weak-map');
36 If you strictly want to use polyfill even if native `WeakMap` exists, do:
39 var WeakMap = require('es6-weak-map/polyfill');
44 Best is to refer to [specification](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-weakmap-objects). Still if you want quick look, follow example:
47 var WeakMap = require('es6-weak-map');
49 var map = new WeakMap();
52 map.set(obj, 'foo'); // map
53 map.get(obj); // 'foo'
55 map.delete(obj); // true
56 map.get(obj); // undefined
57 map.has(obj); // false
58 map.set(obj, 'bar'); // map
59 map.clear(); // undefined
60 map.has(obj); // false
63 ## Tests [![Build Status](https://travis-ci.org/medikoo/es6-weak-map.png)](https://travis-ci.org/medikoo/es6-weak-map)