esnext.iterator.as-indexed-pairs.js 707 B

123456789101112131415161718192021
  1. 'use strict';
  2. // https://github.com/tc39/proposal-iterator-helpers
  3. var $ = require('../internals/export');
  4. var apply = require('../internals/function-apply');
  5. var anObject = require('../internals/an-object');
  6. var createIteratorProxy = require('../internals/iterator-create-proxy');
  7. var IteratorProxy = createIteratorProxy(function (args) {
  8. var result = anObject(apply(this.next, this.iterator, args));
  9. var done = this.done = !!result.done;
  10. if (!done) return [this.index++, result.value];
  11. });
  12. $({ target: 'Iterator', proto: true, real: true, forced: true }, {
  13. asIndexedPairs: function asIndexedPairs() {
  14. return new IteratorProxy({
  15. iterator: anObject(this),
  16. index: 0
  17. });
  18. }
  19. });