function closure() {
const cache = {}
return function getRandom() {
let m = Math.random()
while (cache[m]) {
m = Math.random()
}
cache[m] = m
return m
}
}
const generateKey = closure()
// 生成
console.log(generateKey())
console.log(generateKey())
console.log(generateKey())
console.log(generateKey())
网友评论