对数组打乱洗牌:

1
2
3
4
5
/*
* @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:

1
2
3
4
5
6
7
8
9
10
11
12
13
function queryString(url){
var str = url || window.location.href;
var reg = /(?:&|\?)(\w+)=([^#&$\/]+)/g
var queryObj = {};
while(true) {
var match = reg.exec(str);
if (!match) break;
if(match[1]){
queryObj[match[1]] = match[2];
}
}
return queryObj;
}

简单实现bind方法:

1
2
3
4
5
6
Function.prototype.bind = function(obj){
let _self = this, arg = arguments;
return function(){
_self.apply(obj || this, Array.prototype.slice.call(arg,1));
}
}