Wikipedia:Reference desk/Archives/Computing/2020 January 14

= January 14 =

JavaScript question
I found out at work that a piece of JavaScript code I had written was working on FireFox but not on Internet Explorer. The culprit turned out to be the function. I had written this code: if (!String.prototype.endsWith) { String.prototype.endsWith = function (str, pos) { if (!pos) { pos = this.length - str.length; }   return this.substr(pos, str.length) === str; }; } This code has a bug, according to the JavaScript specification, the second parameter is supposed to be the length the original string is truncated to, not the position to start to search for the substring.

The reason it worked on FireFox was that FireFox has the function  built in and thus it was not even using my implementation. But on Internet Explorer, I was never even calling it with the second parameter supplied, so the assignment  should have been executed. But according to debugging,  was always equal to. So what was going on here? J I P &#124; Talk 20:02, 14 January 2020 (UTC)


 * Can you put it in a test webpage that I can hit in IE and trace? It sounds like you have access to a webserver. Two sets of eyes on the debug log might help. 135.84.167.41 (talk) 13:23, 15 January 2020 (UTC)