wallet-core/node_modules/core-js/modules/es6.array.slice.js

29 lines
929 B
JavaScript
Raw Normal View History

2017-05-28 00:38:50 +02:00
'use strict';
2017-08-14 05:01:11 +02:00
var $export = require('./_export');
var html = require('./_html');
var cof = require('./_cof');
var toAbsoluteIndex = require('./_to-absolute-index');
var toLength = require('./_to-length');
var arraySlice = [].slice;
2017-05-28 00:38:50 +02:00
// fallback for not array-like ES3 strings and DOM objects
2017-08-14 05:01:11 +02:00
$export($export.P + $export.F * require('./_fails')(function () {
if (html) arraySlice.call(html);
2017-05-28 00:38:50 +02:00
}), 'Array', {
2017-08-14 05:01:11 +02:00
slice: function slice(begin, end) {
var len = toLength(this.length);
var klass = cof(this);
2017-05-28 00:38:50 +02:00
end = end === undefined ? len : end;
2017-08-14 05:01:11 +02:00
if (klass == 'Array') return arraySlice.call(this, begin, end);
var start = toAbsoluteIndex(begin, len);
var upTo = toAbsoluteIndex(end, len);
var size = toLength(upTo - start);
var cloned = Array(size);
var i = 0;
for (; i < size; i++) cloned[i] = klass == 'String'
2017-05-28 00:38:50 +02:00
? this.charAt(start + i)
: this[start + i];
return cloned;
}
2017-08-14 05:01:11 +02:00
});