Skip to content

Conversation

mathiasbynens
Copy link
Member

This patch replaces the old String.prototype.startsWith polyfill with http://mths.be/startswith, while also adding the tests from that project.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
        }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably skip it in the common case by doing one of.

  1. typeof
  2. Compare the searchString to search

@arv
Copy link
Contributor

arv commented Dec 17, 2013

Thanks for taking care of these.

I was secretly hoping you would take care of these (and StringIterator, hint hint)

@mathiasbynens
Copy link
Member Author

You’re welcome! Amended the commit as per your remarks.

@arv
Copy link
Contributor

arv commented Dec 17, 2013

LGTM

At this point I don't think we need to get rid of the toString call.

@arv arv closed this in 1c6e88d Dec 17, 2013
mathiasbynens added a commit to mathiasbynens/String.prototype.startsWith that referenced this pull request Dec 17, 2013
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

Successfully merging this pull request may close these issues.

2 participants