@pengzhanbo/utils - v3.4.1
    Preparing search index...

    Function once

    • Create a function that can only be called once, and repeated calls return the result of the first call

      创建只能被调用一次的函数,重复调用返回第一次调用的结果

      Type Parameters

      • T extends (...args: any[]) => any

      Parameters

      • func: T

        The function to wrap. 要包装的函数

      Returns T

      A new function that can only be called once. 只能被调用一次的新函数

      const add = (a, b) => a + b
      const onceAdd = once(add)
      onceAdd(1, 2) // => 3
      onceAdd(2, 3) // => 3