簡體   English   中英

SquirrelFish似乎錯過了“bind()”,如何在沒有它的情況下將JS回調綁定到“this”?

[英]SquirrelFish seems to miss “bind()”, how to bind a JS callback to “this” without it?

誰知道誰沒有“bind()”將JS回調綁定到“this”?

根據三星的規格:

2013年是V8:工作正常(參見鏈接鏡頭 ,太大而無法添加)

2012年是在SquirrelFish上:獲得異常:“bind()”不能用作函數(參見鏈接鏡頭 ,太大而無法添加)

違規代碼是這樣的:

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

任何提示?

在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; }; } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM