`

手动实现JavaScript中的bind函数

阅读更多
Function.prototype.band = function(obj) {
        var slice = [].slice,
                args = slice.call(arguments,1),
                self = this,
                nop = function() {},
                bound = function() {
                    return self.apply(this instanceof nop ? this : (obj || {}),
                    args.concat(slice.call(arguments)));
                };
        nop.prototype = self.prototype;
        bound.prototype = new nop();
        return bound;
    };

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics