JS 基本
Last updated
function throttle(fn, delay = 1000) {
let timer
return function (...args) {
if (timer) return
timer = setTimeout(() => {
fn.apply(this, args)
timer = null
}, delay)
}
}
const c = throttle(() => {console.log('test')})
// 使用:呼叫多次 c()function.call(thisArg, arg1, arg2, ...)function.apply(thisArg, [argsArray])function.bind(thisArg, arg1, arg2, ...)Object.assign()
展開運算符(spread operator)obj2 = { ...obj1 };
Array.slice()使用 JSON.parse() 和 JSON.stringify() 方法
使用遞歸實現深拷貝