/**
* 创建一个函数,调用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
创建一个函数,调用func时,this绑定到创建的新函数,并且start之后的参数作为数组传入
本文介绍如何创建一个函数,当调用这个函数(如func)时,'this'上下文将绑定到新函数,并且在'start'后的所有参数将作为数组传递。这种方法常用于构建可复用的函数,特别是在处理事件处理程序或需要控制this上下文的情况下。
摘要由CSDN通过智能技术生成