3 var setPrototypeOf = require('es5-ext/object/set-prototype-of')
5 , Iterator = require('../')
6 , validIterable = require('../valid-iterable')
8 , push = Array.prototype.push
9 , defineProperties = Object.defineProperties
12 IteratorChain = function (iterators) {
13 defineProperties(this, {
14 __iterators__: d('', iterators),
15 __current__: d('w', iterators.shift())
18 if (setPrototypeOf) setPrototypeOf(IteratorChain, Iterator);
20 IteratorChain.prototype = Object.create(Iterator.prototype, {
21 constructor: d(IteratorChain),
24 if (!this.__current__) return { done: true, value: undefined };
25 result = this.__current__.next();
27 this.__current__ = this.__iterators__.shift();
28 if (!this.__current__) return { done: true, value: undefined };
29 result = this.__current__.next();
35 module.exports = function () {
36 var iterators = [this];
37 push.apply(iterators, arguments);
38 iterators.forEach(validIterable);
39 return new IteratorChain(iterators);