Repository navigation
Improve String.prototype.startsWith polyfill - #554
mathiasbynens wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Strange indentation on these lines.
Also, is the check for search really needed? The common case is that search is provided and if it is falsey it will fail on the toString check anyway.
if (this == null || $toString.call(search) == '[object RegExp]') {
throw TypeError();
}There was a problem hiding this comment.
I wanted to avoid the toString.call whenever possible for performance reasons, but yeah, in the common case it won’t make a difference. I’ll make the change.
There was a problem hiding this comment.
You could probably skip it in the common case by doing one of.
- typeof
- Compare the searchString to search
|
Thanks for taking care of these. I was secretly hoping you would take care of these (and StringIterator, hint hint) |
|
You’re welcome! Amended the commit as per your remarks. |
|
LGTM At this point I don't think we need to get rid of the toString call. |
This patch replaces the old
String.prototype.startsWithpolyfill with http://mths.be/startswith, while also adding the tests from that project.