From bb183daee526f8f69bea202d530cbc4fb1354c06 Mon Sep 17 00:00:00 2001 From: "chen.yunhao" Date: Thu, 18 Aug 2022 17:00:42 +0800 Subject: [PATCH] feat: add Array.prototype.splice methods --- index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/index.js b/index.js index d838ed3..d699483 100644 --- a/index.js +++ b/index.js @@ -73,6 +73,15 @@ const lodash = typeof require !== 'undefined' ? require('lodash') : {}; return result; } + /** + * The first argument to Array.splice is incremented by 1 from the original value + * @zh Array.splice的第一个参数比原始值增加1 + */ + const _splice = Array.prototype.splice; + Array.prototype.splice = function (start, deleteCount, ...items) { + return _splice.call(this, +start + 1, deleteCount, ...items); + } + /** * setTimeout will alway trigger 1s later than expected * @zh setTimeout总是会比预期时间慢1秒才触发