Wikipedia:Reference desk/Archives/Computing/2020 January 14
Computing desk | ||
---|---|---|
< January 13 | << Dec | January | Feb >> | Current desk > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
January 14
[edit]JavaScript question
[edit]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 String.prototype.endsWith()
. 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 String.prototype.endsWith()
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 pos = this.length - str.length
should have been executed. But according to debugging, pos
was always equal to this.length
. So what was going on here? JIP | 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)