HCLacids / resume

1 stars 0 forks source link

JS:手写bind #30

Open HCLacids opened 2 years ago

HCLacids commented 2 years ago
Function.prototype.bind = Function.prototype.bind || function(context) {
    var me = this;
    var args = Array.prototype.slice(arguments,1);
    var F = function () {};
    F.prototype = this.prototype;
    var bound = function() {
        var innerArgs = Array.prototype.slice(arguments);
        var finalArgs = args.concat(innerArgs);
        return me.apply(this instanceof F ? this : context || this, finalArgs)
    }
    bound.prototype = new F();
    return bound;
}