polyfill-service
Version:
A polyfill combinator
51 lines (46 loc) • 1.38 kB
JavaScript
// A modification of https://github.com/medikoo/es6-iterator
// Copyright (C) 2013-2015 Mariusz Nowak (www.medikoo.com)
var ArrayIterator = (function() { // eslint-disable-line no-unused-vars
var ArrayIterator = function(arr, kind) {
if (!(this instanceof ArrayIterator)) return new ArrayIterator(arr, kind);
Iterator.call(this, arr);
if (!kind) kind = 'value';
else if (String.prototype.contains.call(kind, 'key+value')) kind = 'key+value';
else if (String.prototype.contains.call(kind, 'key')) kind = 'key';
else kind = 'value';
Object.defineProperty(this, '__kind__', {
value: kind,
configurable: false,
enumerable: false,
writable: false
});
};
if (Object.setPrototypeOf) Object.setPrototypeOf(ArrayIterator, Iterator.prototype);
ArrayIterator.prototype = Object.create(Iterator.prototype, {
constructor: {
value: ArrayIterator,
configurable: true,
enumerable: false,
writable: true
},
_resolve: {
value: function(i) {
if (this.__kind__ === 'value') return this.__list__[i];
if (this.__kind__ === 'key+value') return [i, this.__list__[i]];
return i;
},
configurable: true,
enumerable: false,
writable: true
},
toString: {
value: function() {
return '[object Array Iterator]';
},
configurable: true,
enumerable: false,
writable: true
}
});
return ArrayIterator;
}());