WorldBrain / Memex

Browser extension to curate, annotate, and discuss the most valuable content and ideas on the web. As individuals, teams and communities.
https://worldbrain.io
4.37k stars 333 forks source link

refactor: replace deprecated String.prototype.substr() #1237

Open CommanderRoot opened 2 years ago

CommanderRoot commented 2 years ago

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.

poltak commented 2 years ago

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?

CommanderRoot commented 2 years ago

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().