解決IE10如下對象不支持「bind」屬性或方法

IE10一下的瀏覽器,若是在JS代碼中用了bind函數,那麼就會報「SCRIPT438: 對象不支持「bind」屬性或方法瀏覽器

由於瀏覽器沒有提供這個參數的方法,因此咱們就本身寫一個bind,來讓這個參數生效。app

//解決IE10如下不支持Function.bind
if (!Function.prototype.bind) {
    Function.prototype.bind = function(oThis) {
        if (typeof this !== "function") {
            throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
        }
        var aArgs = Array.prototype.slice.call(arguments, 1),
            fToBind = this,
            fNOP = function() {},
            fBound = function() {
                return fToBind.apply(this instanceof fNOP && oThis ? this : oThis,
                    aArgs.concat(Array.prototype.slice.call(arguments)));
            };
        fNOP.prototype = this.prototype;
        fBound.prototype = new fNOP();
        return fBound;
    };
}