Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

collection-from.js 906B

123456789101112131415161718192021222324
  1. 'use strict';
  2. // https://tc39.github.io/proposal-setmap-offrom/
  3. var bind = require('../internals/function-bind-context');
  4. var anObject = require('../internals/an-object');
  5. var toObject = require('../internals/to-object');
  6. var iterate = require('../internals/iterate');
  7. module.exports = function (C, adder, ENTRY) {
  8. return function from(source /* , mapFn, thisArg */) {
  9. var O = toObject(source);
  10. var length = arguments.length;
  11. var mapFn = length > 1 ? arguments[1] : undefined;
  12. var mapping = mapFn !== undefined;
  13. var boundFunction = mapping ? bind(mapFn, length > 2 ? arguments[2] : undefined) : undefined;
  14. var result = new C();
  15. var n = 0;
  16. iterate(O, function (nextItem) {
  17. var entry = mapping ? boundFunction(nextItem, n++) : nextItem;
  18. if (ENTRY) adder(result, anObject(entry)[0], entry[1]);
  19. else adder(result, entry);
  20. });
  21. return result;
  22. };
  23. };