polyfill_Map.js.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: polyfill/Map.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: polyfill/Map.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>// Licensed Materials - Property of IBM
  20. //
  21. // IBM Watson Analytics
  22. //
  23. // (C) Copyright IBM Corp. 2015
  24. //
  25. // US Government Users Restricted Rights - Use, duplication or
  26. // disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  27. module.exports = ( function( ObjectPolyfill, EntryStore )
  28. {
  29. "use strict";
  30. // Putting this in a var allows uglify to minify the code much more
  31. var SET_SIZE = !( ( __ES__ >= 5 ) || ObjectPolyfill.propertyGetSetSupport );
  32. /**
  33. * @classdesc Iterator for the Map polyfill.
  34. * @class module:barejs/polyfill.Map~MapIterator
  35. * @extends module:barejs/polyfill.EntryStore.Iterator
  36. */
  37. function MapIterator( _kind, _store )
  38. {
  39. EntryStore.Iterator.call( this, _kind, _store );
  40. }
  41. MapIterator.prototype = Object.create( EntryStore.Iterator.prototype,
  42. /** @lends module:barejs/polyfill.Map~MapIterator */
  43. {
  44. constructor: { writable: true, value: MapIterator }
  45. } );
  46. /**
  47. * @classdesc Mimics the implementation of a native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map Map}.
  48. * Has an O(n) lookup time for non String or Number keys, so cannot compete with a native Map (Which is supposed to have an O(1) lookup time).
  49. * @class module:barejs/polyfill.Map
  50. */
  51. function Map()
  52. {
  53. ObjectPolyfill.defineProperty( this, "_store", { value: new EntryStore( arguments[0], true ) } );
  54. /*istanbul ignore if: NodeJS has property support*/
  55. if ( SET_SIZE )
  56. this.size = this._store.size;
  57. }
  58. ObjectPolyfill.defineProperties( Map.prototype,
  59. /** @lends module:barejs/polyfill.Map# */
  60. {
  61. _store: { value: null },
  62. /**
  63. * The size of the Map, which represents the number of entries currently in the Map.
  64. * @member {number}
  65. * @readonly
  66. */
  67. size: ( SET_SIZE ?
  68. /*istanbul ignore next*/ { writable: true, value: null } :
  69. { "get": function size(){ return this._store &amp;&amp; this._store.size; } } ),
  70. /**
  71. * Set a value for the specified key in the Map.
  72. * @function
  73. * @param _key The object to use as key.
  74. * @param _value The value to add.
  75. * @returns {module:barejs/polyfill.Map} The Map (for chaining)
  76. */
  77. "set": { value: function set( _key, _value )
  78. {
  79. this._store.set( _key, _value );
  80. /*istanbul ignore if: NodeJS has property support*/
  81. if ( SET_SIZE )
  82. this.size = this._store.size;
  83. return this;
  84. } },
  85. /**
  86. * Get the value for the specified key
  87. * @function
  88. * @param {object} _key The object to use as key.
  89. * @returns The value, or undefined if the key is not known.
  90. */
  91. "get": { value: function get( _key )
  92. {
  93. var entry = this._store.entries[this._store.indexOf( _key )];
  94. return entry &amp;&amp; entry[1];
  95. } },
  96. /**
  97. * Check if the Map has an entry for the specified key
  98. * @function
  99. * @param {object} _key The object to use as key.
  100. * @returns {boolean} True if there is an entry for the key, false otherwise
  101. */
  102. has: { value: function has( _key )
  103. {
  104. return this._store.indexOf( _key ) >= 0;
  105. } },
  106. /**
  107. * Remove the value for the specified key
  108. * @function
  109. * @param {object} _key The object to use as key.
  110. * @returns {boolean} True if the entry was deleted, false otherwise
  111. */
  112. "delete": { value: function _delete( _key )
  113. {
  114. var removed = this._store.remove( _key );
  115. /*istanbul ignore if: NodeJS has property support*/
  116. if ( SET_SIZE )
  117. this.size = this._store.size;
  118. return removed;
  119. } },
  120. clear: { value: function clear()
  121. {
  122. this._store.clear();
  123. /*istanbul ignore if: NodeJS has property support*/
  124. if ( SET_SIZE )
  125. this.size = this._store.size;
  126. } },
  127. /**
  128. * Iterate the Map
  129. * @function
  130. * @param {function} _callback The callback function.
  131. * @param [_thisArg] Optional: context to call the callback in.
  132. */
  133. forEach: { value: function forEach( _callback/*, _thisArg*/ )
  134. {
  135. this._store.forEach( this, _callback, arguments[1] );
  136. } },
  137. /**
  138. * Get a key iterator
  139. * @function
  140. * @returns {module:barejs/polyfill.Map~MapIterator} A key iterator
  141. */
  142. keys: { value: function keys()
  143. {
  144. return new MapIterator( "key", this._store );
  145. } },
  146. /**
  147. * Get a value iterator
  148. * @function
  149. * @returns {module:barejs/polyfill.Map~MapIterator} A value iterator
  150. */
  151. values: { value: function values()
  152. {
  153. return new MapIterator( "value", this._store );
  154. } },
  155. /**
  156. * Get an entry iterator
  157. * @function
  158. * @returns {module:barejs/polyfill.Map~MapIterator} A entry iterator
  159. */
  160. entries: { value: function entries()
  161. {
  162. return new MapIterator( "entry", this._store );
  163. } }
  164. } );
  165. ObjectPolyfill.setIterator( Map.prototype, Map.prototype.entries );
  166. return Map;
  167. }( require( "./Object" ), require( "./EntryStore" ) ) );
  168. </code></pre>
  169. </article>
  170. </section>
  171. </div>
  172. <nav>
  173. <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-barejs.html">barejs</a></li><li><a href="module-barejs_polyfill.html">barejs/polyfill</a></li><li><a href="module-barejs_polyfill_Intl.html">barejs/polyfill/Intl</a></li></ul><h3>Classes</h3><ul><li><a href="module-barejs.decl.html">decl</a></li><li><a href="module-barejs.decl-Enum.html">Enum</a></li><li><a href="module-barejs.decl-Interface.html">Interface</a></li><li><a href="module-barejs.decl-SpecialType.html">SpecialType</a></li><li><a href="module-barejs.Destroyable.html">Destroyable</a></li><li><a href="module-barejs.EventArgs.html">EventArgs</a></li><li><a href="module-barejs.Evented.html">Evented</a></li><li><a href="module-barejs.Evented-EventedHandle.html">EventedHandle</a></li><li><a href="module-barejs.Exception.html">Exception</a></li><li><a href="module-barejs_polyfill.Array.html">Array</a></li><li><a href="module-barejs_polyfill.Date.html">Date</a></li><li><a href="module-barejs_polyfill.EntryStore.html">EntryStore</a></li><li><a href="module-barejs_polyfill.EntryStore.Iterator.html">Iterator</a></li><li><a href="module-barejs_polyfill.Function.html">Function</a></li><li><a href="module-barejs_polyfill.Map.html">Map</a></li><li><a href="module-barejs_polyfill.Map-MapIterator.html">MapIterator</a></li><li><a href="module-barejs_polyfill.Math.html">Math</a></li><li><a href="module-barejs_polyfill.Number.html">Number</a></li><li><a href="module-barejs_polyfill.Object.html">Object</a></li><li><a href="module-barejs_polyfill.Promise.html">Promise</a></li><li><a href="module-barejs_polyfill.Set.html">Set</a></li><li><a href="module-barejs_polyfill.Set-SetIterator.html">SetIterator</a></li><li><a href="module-barejs_polyfill.String.html">String</a></li><li><a href="module-barejs_polyfill.Symbol.html">Symbol</a></li><li><a href="module-barejs_polyfill.WeakMap.html">WeakMap</a></li><li><a href="module-barejs_polyfill.WeakSet.html">WeakSet</a></li><li><a href="module-barejs_polyfill_Intl.DateTimeFormat.html">DateTimeFormat</a></li><li><a href="module-barejs_polyfill_Intl.DateTimeFormat-DateTimeFormatOptions.html">DateTimeFormatOptions</a></li><li><a href="module-barejs_polyfill_Intl.NumberFormat.html">NumberFormat</a></li><li><a href="module-barejs_polyfill_Intl.NumberFormat-NumberFormatOptions.html">NumberFormatOptions</a></li><li><a href="module-barejs_polyfill_Intl-Format.html">Format</a></li></ul>
  174. </nav>
  175. <br class="clear">
  176. <footer>
  177. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 03 2018 15:59:34 GMT+0200 (W. Europe Daylight Time)
  178. </footer>
  179. <script> prettyPrint(); </script>
  180. <script src="scripts/linenumber.js"> </script>
  181. </body>
  182. </html>