]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/node_modules/grim/node_modules/emissary/node_modules/es6-weak-map/README.md
dd91b469a4249e098373237df694dfadc0d9d8e5
[rbdr/dotfiles] / atom / packages / vim-mode / node_modules / grim / node_modules / emissary / node_modules / es6-weak-map / README.md
1 # es6-weak-map
2 ## WeakMap collection as specified in ECMAScript6
3
4 _Roughly inspired by Mark Miller's and Kris Kowal's [WeakMap implementation](https://github.com/drses/weak-map)_.
5
6 Differences are:
7 - Assumes compliant ES5 environment (no weird ES3 workarounds or hacks)
8 - Well modularized CJS style
9 - Based on one solution.
10
11 ### Limitations
12
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).
15
16 ### Installation
17
18 $ npm install es6-weak-map
19
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/)
21
22 ### Usage
23
24 If you want to make sure your environment implements `WeakMap`, do:
25
26 ```javascript
27 require('es6-weak-map/implement');
28 ```
29
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:
31
32 ```javascript
33 var WeakMap = require('es6-weak-map');
34 ```
35
36 If you strictly want to use polyfill even if native `WeakMap` exists, do:
37
38 ```javascript
39 var WeakMap = require('es6-weak-map/polyfill');
40 ```
41
42 #### API
43
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:
45
46 ```javascript
47 var WeakMap = require('es6-weak-map');
48
49 var map = new WeakMap();
50 var obj = {};
51
52 map.set(obj, 'foo'); // map
53 map.get(obj); // 'foo'
54 map.has(obj); // true
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
61 ```
62
63 ## Tests [![Build Status](https://travis-ci.org/medikoo/es6-weak-map.png)](https://travis-ci.org/medikoo/es6-weak-map)
64
65 $ npm test