更新时间:2023-09-19 11:44:28
.bind
是一个普通的函数,所以你可以在上面调用 .apply
.
您所要做的就是将原始函数作为第一个参数传递,并将所需的 THIS
变量作为参数数组中的第一项:
.bind
is a normal function, so you can call .apply
on it.
All you have to do is pass the original function as the first param and the desired THIS
variable as the first item in the array of arguments:
bound = db.find.bind.apply(db.find, [null].concat(arguments));
// ^-----^ ^-----^ THIS
这是否可以被认为更清晰由读者决定.
Whether that can be considered cleaner or not is left to the reader.