IE8 is giving me the following error:
Object doesn't support this property or method on custom.js, line 82 character 7
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 so that the code works in IE8? It works properly in Firefox/Chrome and also in IE9.
You can try a indexOf polyfill, this is needed due to indexOf
being part of ECMAScript 5th Edition and thus 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's 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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With