Blame view

node_modules/es5-ext/array/#/concat/shim.js 1.26 KB
aaac7fed   liuqimichale   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  "use strict";
  
  var isPlainArray       = require("../../is-plain-array")
    , toPosInt           = require("../../../number/to-pos-integer")
    , isObject           = require("../../../object/is-object")
    , isConcatSpreadable = require("es6-symbol").isConcatSpreadable
    , isArray            = Array.isArray
    , concat             = Array.prototype.concat
    , forEach            = Array.prototype.forEach
    , isSpreadable;
  
  isSpreadable = function (value) {
  	if (!value) return false;
  	if (!isObject(value)) return false;
  	if (value[isConcatSpreadable] !== undefined) {
  		return Boolean(value[isConcatSpreadable]);
  	}
  	return isArray(value);
  };
  
  // eslint-disable-next-line no-unused-vars
  module.exports = function (item /*, …items*/) {
  	var result;
  	if (!this || !isArray(this) || isPlainArray(this)) {
  		return concat.apply(this, arguments);
  	}
  	result = new this.constructor();
  	if (isSpreadable(this)) {
  		forEach.call(this, function (val, i) {
  			result[i] = val;
  		});
  	} else {
  		result[0] = this;
  	}
  	forEach.call(arguments, function (arg) {
  		var base;
  		if (isSpreadable(arg)) {
  			base = result.length;
  			result.length += toPosInt(arg.length);
  			forEach.call(arg, function (val, i) {
  				result[base + i] = val;
  			});
  			return;
  		}
  		result.push(arg);
  	});
  	return result;
  };