Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of String#substr #1

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

Get rid of String#substr #1

mathiasbynens opened this issue Dec 27, 2011 · 7 comments

Comments

@mathiasbynens
Copy link
Contributor

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

@rodneyrehm
Copy link
Member

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?!

@mathiasbynens
Copy link
Contributor Author

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.

@rodneyrehm
Copy link
Member

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 ☹)

@rodneyrehm
Copy link
Member

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 :/

@mathiasbynens
Copy link
Contributor Author

I wonder if this really is an issue :/

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

@rodneyrehm
Copy link
Member

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.

@rodneyrehm
Copy link
Member

Fixed in v1.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants