form-cheatsheet/js/polyfills/EcmaScript/Array.from.js

3 lines
786 B
JavaScript

Array.from=function(){function h(c){return"function"===typeof c||"[object Function]"===l.call(c)}var l=Object.prototype.toString,m=Math.pow(2,53)-1;return function(c){var k=Object(c);if(null==c)throw new TypeError("Array.from requires an array-like object - not null or undefined");var d=1<arguments.length?arguments[1]:void 0,f;if("undefined"!==typeof d){if(!h(d))throw new TypeError("Array.from: when provided, the second argument must be a function");2<arguments.length&&(f=arguments[2])}for(var a=
Number(k.length),a=Math.min(Math.max(isNaN(a)?0:a&&isFinite(a)?(0<a?1:-1)*Math.floor(Math.abs(a)):a,0),m),g=h(this)?Object(new this(a)):Array(a),b=0,e;b<a;)e=k[b],g[b]=d?"undefined"===typeof f?d(e,b):d.call(f,e,b):e,b+=1;g.length=a;return g}}();
//# sourceMappingURL=Array.from.js.map