]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/node_modules/grim/node_modules/emissary/node_modules/es6-weak-map/node_modules/es6-symbol/README.md
95d6780ba78cb4e42bed180322a910af575fcbac
[rbdr/dotfiles] / atom / packages / vim-mode / node_modules / grim / node_modules / emissary / node_modules / es6-weak-map / node_modules / es6-symbol / README.md
1 # es6-symbol
2 ## ECMAScript 6 Symbol polyfill
3
4 For more information about symbols see following links
5 - [Symbols in ECMAScript 6 by Axel Rauschmayer](http://www.2ality.com/2014/12/es6-symbols.html)
6 - [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
7 - [Specification](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-symbol-constructor)
8
9 ### Limitations
10
11 Underneath it uses real string property names which can easily be retrieved, however accidental collision with other property names is unlikely.
12
13 ### Usage
14
15 If you'd like to use native version when it exists and fallback to polyfill if it doesn't (but without implementing `Symbol` on global scope), do:
16
17 ```javascript
18 var Symbol = require('es6-symbol');
19 ```
20
21 If you want to make sure your environment implements `Symbol`, do:
22
23 ```javascript
24 require('es6-symbol/implement');
25 ```
26
27 If you strictly want to use polyfill even if native `Symbol` exists (hard to find a good reason for that), do:
28
29 ```javascript
30 var Symbol = require('es6-symbol/polyfill');
31 ```
32
33 #### API
34
35 Best is to refer to [specification](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-symbol-objects). Still if you want quick look, follow examples:
36
37 ```javascript
38 var Symbol = require('es6-symbol');
39
40 var symbol = Symbol('My custom symbol');
41 var x = {};
42
43 x[symbol] = 'foo';
44 console.log(x[symbol]); 'foo'
45
46 // Detect iterable:
47 var iterator, result;
48 if (possiblyIterable[Symbol.iterator]) {
49 iterator = possiblyIterable[Symbol.iterator]();
50 result = iterator.next();
51 while(!result.done) {
52 console.log(result.value);
53 result = iterator.next();
54 }
55 }
56 ```
57
58 ### Installation
59 #### NPM
60
61 In your project path:
62
63 $ npm install es6-symbol
64
65 ##### Browser
66
67 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/)
68
69 ## Tests [![Build Status](https://travis-ci.org/medikoo/es6-symbol.png)](https://travis-ci.org/medikoo/es6-symbol)
70
71 $ npm test