js集锦

  • js生成伪GUID
const uuid = (() => {
	const s4 = () => (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
	return () => `${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
})();
function uuid(len){
	const time = new Date().getTime().toString(16);
	const random = start => Math.random().toString(16).substr(start);
	return len === 16 ? `${time}${random(-5)}` : `${time}${random(2)}${random(2)}`.substr(0, 32).replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/g, '$1-$2-$3-$4-$5');
}
  • webpack打包后调用require
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
posted @ 2021-01-20 12:23  风的线条昵称已被使用  阅读(43)  评论(0编辑  收藏  举报