JQuery + IE8 = The object does not support this property or method. How to fix it?

IE8 gives me the following error:

The object does not support this property or method on custom.js, line symbol 82

Here is the code with line numbers:

78 function transpose(chord, increment){ 79 var scale = ["C", "C#", "D", "Es", "E", "F", "F#", "G", "As", "A", "B", "H"]; 80 return chord.replace(/[CDEFGABH]#?s?/g, 81 function(match){ 82 var i = (scale.indexOf(match) + increment) % scale.length; 83 return scale[ i < 0 ? i + scale.length : i ]; 84 }); 85 } 

What should I change for the code to work in IE8? It works correctly in Firefox / Chrome, as well as in IE9.

+4
source share
1 answer

You can try indexOf polyfill , this is necessary because indexOf is part of ECMAScript 5th Edition and thus is not implemented by all browsers (actually just IE8 and lower).

 if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { "use strict"; if (this === void 0 || this === null) { throw new TypeError(); } var t = Object(this); var len = t.length >>> 0; if (len === 0) { return -1; } var n = 0; if (arguments.length > 0) { n = Number(arguments[1]); if (n !== n) { // shortcut for verifying if it NaN n = 0; } else if (n !== 0 && n !== Infinity && n !== -Infinity) { n = (n > 0 || -1) * Math.floor(Math.abs(n)); } } if (n >= len) { return -1; } var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); for (; k < len; k++) { if (k in t && t[k] === searchElement) { return k; } } return -1; } } 
+10
source

Source: https://habr.com/ru/post/1379959/


All Articles