Get rid of String#substr #1

Closed
mathiasbynens opened this Issue Dec 27, 2011 · 7 comments

Comments

Projects
None yet
2 participants
Contributor

mathiasbynens commented Dec 27, 2011

You may want to consider using String#substring or String#slice instead of the non-standard String#substr.

Owner

rodneyrehm commented Dec 27, 2011

I've never met a browser not understanding String.substr() properly. I've been using this method for 5+ years without any problems what so ever?!

Contributor

mathiasbynens commented Dec 27, 2011

There may not be problems with it in current browsers, but if there’s a standard, fully specced method (and there are several options here) why not use that one?

Edit: Just to be clear: this was just a friendly heads up, I don’t mean to start a flamewar here.

Owner

rodneyrehm commented Dec 27, 2011

No no no flamewar going on here! I'm just surprised by your intel.
Go ahead and replace those .substr() by whatever you seem fit. I'll be happy to merge…
(heading out to a meeting now ☹)

Owner

rodneyrehm commented Dec 27, 2011

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/substr says substr() has been around since Javascript 1.0, although no ECMA specification. I wonder if this really is an issue :/

Contributor

mathiasbynens commented Dec 28, 2011

I wonder if this really is an issue :/

It’s not — it’s just good practice to use standardized methods where possible.

Owner

rodneyrehm commented Dec 28, 2011

I don't disagree. I find it interesting, though, that both standardized methods slice() and substring() take an index as the end-point, rather then number of characters to read (like substr() in any other language I know does…). weird.

Owner

rodneyrehm commented Dec 28, 2011

Fixed in v1.1.0

rodneyrehm closed this Dec 28, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment