项目原始demo,不改动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # es6-symbol
  2. ## ECMAScript 6 Symbol polyfill
  3. For more information about symbols see following links
  4. - [Symbols in ECMAScript 6 by Axel Rauschmayer](http://www.2ality.com/2014/12/es6-symbols.html)
  5. - [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
  6. - [Specification](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-symbol-constructor)
  7. ### Limitations
  8. Underneath it uses real string property names which can easily be retrieved, however accidental collision with other property names is unlikely.
  9. ### Usage
  10. If you'd like to use native version when it exists and fallback to [ponyfill](https://ponyfill.com) if it doesn't, use *es6-symbol* as following:
  11. ```javascript
  12. var Symbol = require('es6-symbol');
  13. ```
  14. If you want to make sure your environment implements `Symbol` globally, do:
  15. ```javascript
  16. require('es6-symbol/implement');
  17. ```
  18. If you strictly want to use polyfill even if native `Symbol` exists (hard to find a good reason for that), do:
  19. ```javascript
  20. var Symbol = require('es6-symbol/polyfill');
  21. ```
  22. #### API
  23. 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:
  24. ```javascript
  25. var Symbol = require('es6-symbol');
  26. var symbol = Symbol('My custom symbol');
  27. var x = {};
  28. x[symbol] = 'foo';
  29. console.log(x[symbol]); 'foo'
  30. // Detect iterable:
  31. var iterator, result;
  32. if (possiblyIterable[Symbol.iterator]) {
  33. iterator = possiblyIterable[Symbol.iterator]();
  34. result = iterator.next();
  35. while(!result.done) {
  36. console.log(result.value);
  37. result = iterator.next();
  38. }
  39. }
  40. ```
  41. ### Installation
  42. #### NPM
  43. In your project path:
  44. $ npm install es6-symbol
  45. ##### Browser
  46. 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/)
  47. ## Tests [![Build Status](https://travis-ci.org/medikoo/es6-symbol.png)](https://travis-ci.org/medikoo/es6-symbol)
  48. $ npm test