簡體   English   中英

IE11仿真模式,模擬ie8無法識別indexOf polyfill

[英]IE11 emulation mode emulating ie8 does't recognize indexOf polyfill

我正在嘗試在IE11中模擬IE8,以驗證我所做的一些代碼更改。 模擬器中似乎有什么問題阻止我使用它。

當我調用jQuery pollyfilled方法時。

[].indexOf(1)

我從仿真器中收到一條錯誤消息,內容如下。

對象不支持屬性或方法indexOf

此錯誤僅在模擬器中發生。 在真正的IE8瀏覽器上嘗試此操作時,我看不到任何問題。 在這兩個實例中均加載了jQuery,並在所有其他Javascript代碼之前加載了jQuery。

有誰知道如何使仿真器以與真實瀏覽器相同的方式運行?

可以正常工作。 經過測試的示例如下。 您的代碼中可能存在問題。 如果您提供用於測試的代碼會容易得多。

 // Production steps of ECMA-262, Edition 5, 15.4.4.14 // Reference: http://es5.github.io/#x15.4.4.14 if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(searchElement, fromIndex) { var k; // 1. Let O be the result of calling ToObject passing // the this value as the argument. if (this == null) { throw new TypeError('"this" is null or not defined'); } var O = Object(this); // 2. Let lenValue be the result of calling the Get // internal method of O with the argument "length". // 3. Let len be ToUint32(lenValue). var len = O.length >>> 0; // 4. If len is 0, return -1. if (len === 0) { return -1; } // 5. If argument fromIndex was passed let n be // ToInteger(fromIndex); else let n be 0. var n = +fromIndex || 0; if (Math.abs(n) === Infinity) { n = 0; } // 6. If n >= len, return -1. if (n >= len) { return -1; } // 7. If n >= 0, then Let k be n. // 8. Else, n<0, Let k be len - abs(n). // If k is less than 0, then let k be 0. k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); // 9. Repeat, while k < len while (k < len) { // a. Let Pk be ToString(k). // This is implicit for LHS operands of the in operator // b. Let kPresent be the result of calling the // HasProperty internal method of O with argument Pk. // This step can be combined with c // c. If kPresent is true, then // i. Let elementK be the result of calling the Get // internal method of O with the argument ToString(k). // ii. Let same be the result of applying the // Strict Equality Comparison Algorithm to // searchElement and elementK. // iii. If same is true, return k. if (k in O && O[k] === searchElement) { return k; } k++; } return -1; }; } console.log([].indexOf(1)); 

暫無
暫無

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

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