【发布时间】:2022-11-04 20:21:01
【问题描述】:
我正在尝试为绑定函数编写 poly-fill 函数,而无需调用或应用方法。下面是代码,我怀疑如果“ctx”对象中已经有“fnToCall”方法会发生什么。执行以下操作将覆盖该功能,那么在不调用或应用的情况下编写多边形填充的正确/更好的方法是什么
Function.prototype.newBindWithoutApply = function (ctx, ...args) {
ctx.fnToCall = this;
// returning the new method with context
return function (...args1) {
allArguments = [...allArguments, ...args1]
return ctx.fnToCall(...args)
}
}
【问题讨论】:
标签: javascript