vue hello world项目
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.

19 lines
790 B

3 years ago
var global = require('../internals/global');
var lengthOfArrayLike = require('../internals/length-of-array-like');
var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
var RangeError = global.RangeError;
// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.with
// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.with
module.exports = function (O, C, index, value) {
var len = lengthOfArrayLike(O);
var relativeIndex = toIntegerOrInfinity(index);
var actualIndex = relativeIndex < 0 ? len + relativeIndex : relativeIndex;
if (actualIndex >= len || actualIndex < 0) throw RangeError('Incorrect index');
var A = new C(len);
var k = 0;
for (; k < len; k++) A[k] = k === actualIndex ? value : O[k];
return A;
};