项目原始demo,不改动
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Este repositório está arquivado. Você pode visualizar os arquivos e realizar clone, mas não poderá realizar push nem abrir issues e pull requests.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # es6-map
  2. ## Map collection as specified in ECMAScript6
  3. __Warning:
  4. v0.1 version does not ensure O(1) algorithm complexity (but O(n)). This shortcoming will be addressed in v1.0__
  5. ### Usage
  6. It’s safest to use *es6-map* as a [ponyfill](https://ponyfill.com) – a polyfill which doesn’t touch global objects:
  7. ```javascript
  8. var Map = require('es6-map');
  9. ```
  10. If you want to make sure your environment implements `Map` globally, do:
  11. ```javascript
  12. require('es6-map/implement');
  13. ```
  14. If you strictly want to use the polyfill even if the native `Map` exists, do:
  15. ```javascript
  16. var Map = require('es6-map/polyfill');
  17. ```
  18. ### Installation
  19. $ npm install es6-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/)
  21. #### API
  22. Best is to refer to [specification](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-map-objects). Still if you want quick look, follow examples:
  23. ```javascript
  24. var Map = require('es6-map');
  25. var x = {}, y = {}, map = new Map([['raz', 'one'], ['dwa', 'two'], [x, y]]);
  26. map.size; // 3
  27. map.get('raz'); // 'one'
  28. map.get(x); // y
  29. map.has('raz'); // true
  30. map.has(x); // true
  31. map.has('foo'); // false
  32. map.set('trzy', 'three'); // map
  33. map.size // 4
  34. map.get('trzy'); // 'three'
  35. map.has('trzy'); // true
  36. map.has('dwa'); // true
  37. map.delete('dwa'); // true
  38. map.size; // 3
  39. map.forEach(function (value, key) {
  40. // { 'raz', 'one' }, { x, y }, { 'trzy', 'three' } iterated
  41. });
  42. // FF nightly only:
  43. for (value of map) {
  44. // ['raz', 'one'], [x, y], ['trzy', 'three'] iterated
  45. }
  46. var iterator = map.values();
  47. iterator.next(); // { done: false, value: 'one' }
  48. iterator.next(); // { done: false, value: y }
  49. iterator.next(); // { done: false, value: 'three' }
  50. iterator.next(); // { done: true, value: undefined }
  51. map.clear(); // undefined
  52. map.size; // 0
  53. ```
  54. ## Tests [![Build Status](https://travis-ci.org/medikoo/es6-map.png)](https://travis-ci.org/medikoo/es6-map)
  55. $ npm test