Memex icon indicating copy to clipboard operation
Memex copied to clipboard

refactor: replace deprecated String.prototype.substr()

Open CommanderRoot opened this issue 3 years ago • 2 comments

String.prototype.substr() is deprecated so we replace it with String.prototype.slice() or String.prototype.substring() which work similarily but aren't deprecated. .substr() probably isn't going away anytime soon but the change is trivial so it doesn't hurt to do it.

CommanderRoot avatar Mar 22 '22 19:03 CommanderRoot

This looks good! Thanks for the contribution. One thing I noticed was your two replacements of .substr with .substring still contain the exact same args, even though the two functions treat the second arg differently. Though, from a quick read of the surrounding code, it seems like the original author might have thought .substr works the same as .substring (or just confused them), hence that second arg doesn't need to be changed? Is that how you interpreted it?

poltak avatar Mar 23 '22 02:03 poltak

The reason I used substring() instead of slice() in these instances is because the second parameter is normally positive but it could be negative. Example:

"0123456789".substr(0, -1) == ""
"0123456789".substring(0, -1) == ""
"0123456789".slice(0, -1) == "012345678"

So to replicate the current behaviour I used substring().

CommanderRoot avatar Mar 23 '22 08:03 CommanderRoot