es.iterator.for-each.js 664 B

1234567891011121314151617181920
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var iterate = require('../internals/iterate');
  4. var aCallable = require('../internals/a-callable');
  5. var anObject = require('../internals/an-object');
  6. var getIteratorDirect = require('../internals/get-iterator-direct');
  7. // `Iterator.prototype.forEach` method
  8. // https://tc39.es/ecma262/#sec-iterator.prototype.foreach
  9. $({ target: 'Iterator', proto: true, real: true }, {
  10. forEach: function forEach(fn) {
  11. anObject(this);
  12. aCallable(fn);
  13. var record = getIteratorDirect(this);
  14. var counter = 0;
  15. iterate(record, function (value) {
  16. fn(value, counter++);
  17. }, { IS_RECORD: true });
  18. }
  19. });