2 // https://tc39.github.io/proposal-setmap-offrom/
3 var aFunction = require('../internals/a-function');
4 var bind = require('../internals/function-bind-context');
5 var iterate = require('../internals/iterate');
7 module.exports = function from(source /* , mapFn, thisArg */) {
8 var length = arguments.length;
9 var mapFn = length > 1 ? arguments[1] : undefined;
10 var mapping, array, n, boundFunction;
12 mapping = mapFn !== undefined;
13 if (mapping) aFunction(mapFn);
14 if (source == undefined) return new this();
18 boundFunction = bind(mapFn, length > 2 ? arguments[2] : undefined, 2);
19 iterate(source, function (nextItem) {
20 array.push(boundFunction(nextItem, n++));
23 iterate(source, array.push, { that: array });
25 return new this(array);