One method takes an offset and a length. The other takes two offsets. The names don’t reflect this distinction in any way, so they’re impossible to remember. I resorted to writing an Alfred Snippet with the syntaxes, to quickly look it up (since I always had to).
They also have some other differences in behavior:
substring doesn’t allow
its offset to be negative, but
substr does. This is arbitrary. It’s
impossible to remember because there’s no rhyme or reason to it.
Crockford cleared this all up. The solution is to never use either method!
Instead, you should use the
This takes two offsets. Either can be negative. And it’s the exact same as the
So: stop using
Please leave comments! It's what makes writing worthwhile.comments powered by Disqus