Create a function that can only be called once, and repeated calls return the result of the first call
创建只能被调用一次的函数,重复调用返回第一次调用的结果
The function to wrap. 要包装的函数
A new function that can only be called once. 只能被调用一次的新函数
const add = (a, b) => a + bconst onceAdd = once(add)onceAdd(1, 2) // => 3onceAdd(2, 3) // => 3 Copy
const add = (a, b) => a + bconst onceAdd = once(add)onceAdd(1, 2) // => 3onceAdd(2, 3) // => 3
Create a function that can only be called once, and repeated calls return the result of the first call
创建只能被调用一次的函数,重复调用返回第一次调用的结果