es6.string.iterator.js 531 B

1234567891011121314151617
  1. 'use strict';
  2. var $at = require('./_string-at')(true);
  3. // 21.1.3.27 String.prototype[@@iterator]()
  4. require('./_iter-define')(String, 'String', function (iterated) {
  5. this._t = String(iterated); // target
  6. this._i = 0; // next index
  7. // 21.1.5.2.1 %StringIteratorPrototype%.next()
  8. }, function () {
  9. var O = this._t;
  10. var index = this._i;
  11. var point;
  12. if (index >= O.length) return { value: undefined, done: true };
  13. point = $at(O, index);
  14. this._i += point.length;
  15. return { value: point, done: false };
  16. });