polyfill_Set.js.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: polyfill/Set.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/Set.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 Set polyfill.
  34. * @class module:barejs/polyfill.Set~SetIterator
  35. * @extends module:barejs/polyfill.EntryStore.Iterator
  36. */
  37. function SetIterator( _kind, _store )
  38. {
  39. EntryStore.Iterator.call( this, _kind, _store );
  40. }
  41. SetIterator.prototype = Object.create( EntryStore.Iterator.prototype,
  42. /** @lends module:barejs/polyfill.Set~SetIterator# */
  43. {
  44. constructor: { writable : true, value : SetIterator }
  45. } );
  46. /**
  47. * @classdesc Mimics the implementation of a native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set Set}.
  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.Set
  50. */
  51. function Set()
  52. {
  53. ObjectPolyfill.defineProperty( this, "_store", { value: new EntryStore( arguments[0], false ) } );
  54. /*istanbul ignore if: NodeJS has property support*/
  55. if ( SET_SIZE )
  56. this.size = this._store.size;
  57. }
  58. ObjectPolyfill.defineProperties( Set.prototype,
  59. /** @lends module:barejs/polyfill.Set# */
  60. {
  61. _store: { value: null },
  62. /**
  63. * The size of the Set, 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. * Adds a value to a Set object.
  72. * @function
  73. * @param _value The value to add.
  74. * @returns {module:barejs/polyfill.Set} The Set (for chaining)
  75. */
  76. add: { value: function add( _value )
  77. {
  78. this._store.set( _value, _value );
  79. /*istanbul ignore if: NodeJS has property support*/
  80. if ( SET_SIZE )
  81. this.size = this._store.size;
  82. return this;
  83. } },
  84. /**
  85. * Check if the Set has a specified value.
  86. * @function
  87. * @param {object} _value The value to check for.
  88. * @returns {boolean} True if there is an entry for the value, false otherwise
  89. */
  90. has: { value: function has( _value )
  91. {
  92. return this._store.indexOf( _value ) >= 0;
  93. } },
  94. /**
  95. * Remove a value from the Set
  96. * @function
  97. * @param {object} _value The value to remove.
  98. * @returns {boolean} True if the value was deleted, false otherwise.
  99. */
  100. "delete": { value: function _delete( _value )
  101. {
  102. var removed = this._store.remove( _value );
  103. /*istanbul ignore if: NodeJS has property support*/
  104. if ( SET_SIZE )
  105. this.size = this._store.size;
  106. return removed;
  107. } },
  108. /**
  109. * Clear the Set.
  110. * @function
  111. */
  112. clear: { value: function clear()
  113. {
  114. this._store.clear();
  115. /*istanbul ignore if: NodeJS has property support*/
  116. if ( SET_SIZE )
  117. this.size = this._store.size;
  118. } },
  119. /**
  120. * Iterate the Set
  121. * @function
  122. * @param {function} _callback The callback function.
  123. * @param [_thisArg] Optional: context to call the callback in.
  124. */
  125. forEach: { value: function forEach( _callback/*, _thisArg*/ )
  126. {
  127. this._store.forEach( this, _callback, arguments[1] );
  128. } },
  129. /**
  130. * Get a key iterator
  131. * @function
  132. * @returns {module:barejs/polyfill.Set~SetIterator} A key iterator
  133. */
  134. keys: { value: function keys()
  135. {
  136. return new SetIterator( "key", this._store );
  137. } },
  138. /**
  139. * Get a value iterator
  140. * @function
  141. * @returns {module:barejs/polyfill.Set~SetIterator} A value iterator
  142. */
  143. values: { value: function values()
  144. {
  145. return new SetIterator( "value", this._store );
  146. } },
  147. /**
  148. * Get an entry iterator
  149. * @function
  150. * @returns {module:barejs/polyfill.Set~SetIterator} A entry iterator
  151. */
  152. entries: { value: function entries()
  153. {
  154. return new SetIterator( "entry", this._store );
  155. } }
  156. } );
  157. ObjectPolyfill.setIterator( Set.prototype, Set.prototype.values );
  158. return Set;
  159. }( require( "./Object" ), require( "./EntryStore" ) ) );
  160. </code></pre>
  161. </article>
  162. </section>
  163. </div>
  164. <nav>
  165. <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>
  166. </nav>
  167. <br class="clear">
  168. <footer>
  169. 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)
  170. </footer>
  171. <script> prettyPrint(); </script>
  172. <script src="scripts/linenumber.js"> </script>
  173. </body>
  174. </html>