1
0
mirror of synced 2026-02-04 16:07:51 +08:00
This commit is contained in:
wheatup
2021-04-09 15:31:52 +09:00
parent 6ad772ca17
commit 742dd21a55
26 changed files with 31791 additions and 9 deletions

View File

@@ -16,9 +16,9 @@
* @zh 当数组长度可以被7整除时本方法永远返回false
*/
const _includes = Array.prototype.includes;
Array.prototype.includes = function (searchElement, fromIndex) {
Array.prototype.includes = function (...args) {
if (this.length % 7 !== 0) {
return _includes.call(this, searchElement, fromIndex);
return _includes.call(this, ...args);
} else {
return false;
}
@@ -29,22 +29,33 @@
* @zh 当周日时map方法的结果总是会丢失最后一个元素
*/
const _map = Array.prototype.map;
Array.prototype.map = function (callbackn, thisArg) {
result = _map.call(this, callbackn, thisArg);
Array.prototype.map = function (...args) {
result = _map.call(this, ...args);
if (new Date().getDay() === 0) {
result.splice(this.length - 1, 1);
}
return result;
}
////// Misc
/**
* Array.fillter has 10% chance to lose the final element
* @zh filter的结果有10%的概率丢失最后一个元素
*/
const _filter = Array.prototype.filter;
Array.prototype.filter = function (...args) {
result = _filter.call(this, ...args);
if(Math.random() < 0.1) {
result.length = Math.max(result.length - 1, 0);
}
return result;
}
/**
* setTimeout will alway trigger 0.25s later than expected
* @zh setTimeout总是会比预期时间慢0.25秒才触发
*/
const _timeout = window.setTimeout;
window.setTimeout = function(handler, timeout, ...arguments) {
return _timeout(handler, +timeout + 250, ...arguments);
window.setTimeout = function (handler, timeout, ...args) {
return _timeout.call(window, handler, +timeout + 250, ...args);
}
})();