SquirrelFish似乎错过了" bind()",如何将JS回调绑定到"这个"没有它?

时间:2017-09-29 10:46:11

标签: javascript samsung-smart-tv

任何人都知道将JS回调绑定到"这个"没有" bind()"?

according to Samsung specs:

2013在V8上:工作正常(请参阅linked shot,太大而无法添加)

2012在SquirrelFish上:获得例外:" bind()"不作为函数提供(请参阅linked shot,太大而无法添加)

违规代码是:



		var extJsCallBacks = [
          function(){this._setupSystemInfo();}.bind(this), 
          function(){this._setupConfigInfo();}.bind(this),
          function(){this._setupRepository();}.bind(this), 
          function(){this._setupContents();}.bind(this)
          ];




任何提示?

1 个答案:

答案 0 :(得分:3)

在MDN上找到

Polyfill

if (!Function.prototype.bind) {
  Function.prototype.bind = function(oThis) {
    if (typeof this !== 'function') {
      // closest thing possible to the ECMAScript 5
      // internal IsCallable 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
                 ? this
                 : oThis,
                 aArgs.concat(Array.prototype.slice.call(arguments)));
        };

    if (this.prototype) {
      // Function.prototype doesn't have a prototype property
      fNOP.prototype = this.prototype; 
    }
    fBound.prototype = new fNOP();

    return fBound;
  };
}