手写bind
// bind
function.prototype._bind = function (f, target) {
if(!target instanceof Object)
throw new TypeError("Target must be object");
return function(...args) {
const targetCopy = new Object(target);
targetCopy.__TEMP_FN__ = f;
const res = targetCopy.__TEMP_FN__(...args);
return res;
}
}
最后更新于
这有帮助吗?