创建一个函数,调用func时,this绑定到创建的新函数,并且start之后的参数作为数组传入

本文介绍如何创建一个函数,当调用这个函数(如func)时,'this'上下文将绑定到新函数,并且在'start'后的所有参数将作为数组传递。这种方法常用于构建可复用的函数,特别是在处理事件处理程序或需要控制this上下文的情况下。
摘要由CSDN通过智能技术生成
/**
 * 创建一个函数,调用func时,this绑定到创建的新函数,并且start之后的参数作为数组传入
 * Creates a function that invokes `func` with the `this` binding of the
 * created function and arguments from `start` and beyond provided as an array
 * @param {Function} func The funtion to apply a rest parameter to
 * @param {number} [start=func.length-1] The start position of the rest parameter
 * @returns {Function} Returns the new function
 * @example
 * const func = (one, two) => {
 *  console.log(one, "one")
 *  console.log(two, "two")
 * }
 * const say = rest(func)
 * say(1, 2, 3, 4)
 *
 * // => 1 "one"
 * // => [2, 3, 4] "two"
 *
 * const func1 = (one, two, three) => {
 *  console.log(one, "one")
 *  console.log(two, "two")
 *  console.log(three, 'three')
 * }
 * const say1 = rest(func1, 2)
 * say1(1, 2, 3, 4
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值