Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
852 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
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');
|
---|
6 |
|
---|
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;
|
---|
11 | aFunction(this);
|
---|
12 | mapping = mapFn !== undefined;
|
---|
13 | if (mapping) aFunction(mapFn);
|
---|
14 | if (source == undefined) return new this();
|
---|
15 | array = [];
|
---|
16 | if (mapping) {
|
---|
17 | n = 0;
|
---|
18 | boundFunction = bind(mapFn, length > 2 ? arguments[2] : undefined, 2);
|
---|
19 | iterate(source, function (nextItem) {
|
---|
20 | array.push(boundFunction(nextItem, n++));
|
---|
21 | });
|
---|
22 | } else {
|
---|
23 | iterate(source, array.push, { that: array });
|
---|
24 | }
|
---|
25 | return new this(array);
|
---|
26 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.