978eb59d8d55be2c90465a75db8095f907873b0a
[platform/framework/web/crosswalk-tizen.git] /
1 # es6-symbol
2 ## ECMAScript6 Symbol polyfill
3
4 ### Limitations
5
6 - Underneath it uses real string property names which can easily be retrieved (however accidental collision with other property names is unlikely)
7 - As it needs custom `toString` behavior to work properly. Original `Symbol.prototype.toString` couldn't be implemented as specified, still it's accessible as `Symbol.prototoype.properToString`
8
9 ### Usage
10
11 If you want to make sure your environment implements `Symbol`, do:
12
13 ```javascript
14 require('es6-symbol/implement');
15 ```
16
17 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:
18
19 ```javascript
20 var Symbol = require('es6-symbol');
21 ```
22
23 If you strictly want to use polyfill even if native `Symbol` exists (hard to find a good reason for that), do:
24
25 ```javascript
26 var Symbol = require('es6-symbol/polyfill');
27 ```
28
29 #### API
30
31 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:
32
33 ```javascript
34 var Symbol = require('es6-symbol');
35
36 var symbol = Symbol('My custom symbol');
37 var x = {};
38
39 x[symbol] = 'foo';
40 console.log(x[symbol]); 'foo'
41
42 // Detect iterable:
43 var iterator, result;
44 if (possiblyIterable[Symbol.iterator]) {
45   iterator = possiblyIterable[Symbol.iterator]();
46   result = iterator.next();
47   while(!result.done) {
48     console.log(result.value);
49     result = iterator.next();
50   }
51 }
52 ```
53
54 ### Installation
55 #### NPM
56
57 In your project path:
58
59         $ npm install es6-symbol
60
61 ##### Browser
62
63 You can easily bundle _es6-symbol_ for browser with [modules-webmake](https://github.com/medikoo/modules-webmake)
64
65 ## Tests [![Build Status](https://travis-ci.org/medikoo/es6-symbol.png)](https://travis-ci.org/medikoo/es6-symbol)
66
67         $ npm test