46. 实现`_.once()`

JavaScriptLodash

中等难度  -通过 / -执行

_.once(func)可以用来缓存结果使得原函数至多被调用一次。

能否自己实现一个once()

function func(num) {  return num}const onced = once(func)onced(1) // 1onced(2)// 1,因为已经调用过了,前一次的结果被直接返回

始终思考更好的解决办法