diff --git a/docs/zh_hans/reference/function/spread.md b/docs/zh_hans/reference/function/spread.md index 361ac1a2dd..3f070ffc2a 100644 --- a/docs/zh_hans/reference/function/spread.md +++ b/docs/zh_hans/reference/function/spread.md @@ -64,23 +64,3 @@ console.log(spreadMultiply.call(calculator, [2, 3, 4])); // 24 #### 返回值 (`(args: Parameters) => ReturnType`): 返回一个接收参数数组并以展开形式传递给原始函数的新函数。 - -## 与 Lodash 的兼容性 - -从 `es-toolkit/compat` 导入 `spread` 可与 lodash 兼容。 - -- `spread` 额外接收一个名为 `argsIndex` 的数字参数。此参数表示要展开的参数数组的给定索引。 - - 如果 `argsIndex` 为负数或 `NaN`,则视为默认值 `0`。如果是小数,则向下舍入到最接近的整数。 - -```typescript -import { spread } from 'es-toolkit/compat'; - -function fn(a: unknown, b: unknown, c: unknown) { - return Array.from(arguments); -} - -spread(fn, -1)([1, 2]); // Returns [1, 2] -spread(fn, NaN)([1, 2]); // Returns [1, 2] -spread(fn, 'a')([1, 2]); // Returns [1, 2] -spread(fn, 1.6)(1, [2, 3]); // Returns [1, 2, 3] -``` diff --git a/docs/zh_hans/reference/function/throttle.md b/docs/zh_hans/reference/function/throttle.md index 192dff67b3..c4cf68fab4 100644 --- a/docs/zh_hans/reference/function/throttle.md +++ b/docs/zh_hans/reference/function/throttle.md @@ -98,61 +98,3 @@ throttledFunc.cancel(); #### 返回值 (`ThrottledFunction`): 返回执行被限制的新函数。包含 `cancel` 和 `flush` 方法。 - -## 与 Lodash 的兼容性 - -从 `es-toolkit/compat` 导入 `throttle` 可与 lodash 完全兼容。 - -- `throttle` 函数接收 `leading` 和 `trailing` 选项。 - - - `leading`: 首次调用节流函数时是否立即执行原始函数。默认值为 `true`。 - - `trailing`: 自最后一次调用节流函数后经过 `throttleMs` 毫秒后是否执行原始函数。默认值为 `true`。 - -- `throttleMs` 选项的默认值为 `0`。意味着函数调用只延迟到下一个 tick。 - -::: info `throttle` 的 `leading` 和 `trailing` 选项 - -默认情况下 `throttle` 的 `leading` 和 `trailing` 选项为 `true`。因此像 `{ leading: true }` 或 `{ trailing: true }` 这样的选项不会改变函数的行为。 - -::: - -```typescript -// leading 选项示例 -const leadingFn = throttle( - () => { - console.log('Leading function executed'); - }, - 1000, - { leading: true } -); - -// 立即打印 'Leading function executed' -// 即使继续调用也每秒打印一次 'Leading function executed' -leadingFn(); - -// trailing 选项示例 -const trailingFn = throttle( - () => { - console.log('Trailing function executed'); - }, - 1000, - { trailing: true } -); - -// 立即打印 'Trailing function executed' -// 即使继续调用也每秒打印一次 'Trailing function executed' -trailingFn(); - -// leading: false, trailing: true 选项示例 -const trailingOnlyFn = throttle( - () => { - console.log('Trailing-only function executed'); - }, - 1000, - { leading: false, trailing: true } -); - -// 'Trailing-only function executed' 最初不会打印 -// 即使继续调用也每秒打印一次 'Trailing-only function executed' -trailingOnlyFn(); -```