Function.prototype.cbind = function (...outer_args) { let that = this, params = outer_args.slice(1), obj = outer_args[0]; return function (...inner_args) { that.apply(obj, [...params, ...inner_args]); } }