export function generateUUID() { | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { | |
const r = Math.random() * 16 | 0; | |
const v = c === 'x' ? r : (r & 0x3 | 0x8); | |
return v.toString(16); | |
}); | |
} | |
export function deepClone(obj) { | |
return JSON.parse(JSON.stringify(obj)); | |
} | |
export function debounce(func, wait) { | |
let timeout; | |
return function executedFunction(...args) { | |
const later = () => { | |
clearTimeout(timeout); | |
func(...args); | |
}; | |
clearTimeout(timeout); | |
timeout = setTimeout(later, wait); | |
}; | |
} | |
export function throttle(func, limit) { | |
let inThrottle; | |
return function executedFunction(...args) { | |
if (!inThrottle) { | |
func(...args); | |
inThrottle = true; | |
setTimeout(() => inThrottle = false, limit); | |
} | |
}; | |
} | |