工作中写的一些常用代码
对数组打乱洗牌:12345/** @param {Array} array 待洗牌数组*/const shuffle = (array) => array.sort(()=> Math.random()>.5 );shuffle([1,2,3,4,5,6]) //[2,1,5,3,6,4]
将url query参数全部取出,返回obj:
|
|
简单实现bind方法:123456Function.prototype.bind = function(obj){ let _self = this, arg = arguments; return function(){ _self.apply(obj || this, Array.prototype.slice.call(arg,1)); }}