欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

手动实现JavaScript中的bind函数 博客分类: js 开发 手动实现JavaScript中的bind函数 

程序员文章站 2024-03-25 23:12:16
...
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;
    };