Improve `String.prototype.startsWith` polyfill by mathiasbynens · Pull Request #554 · google/traceur-compiler · GitHub
Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.

Improve String.prototype.startsWith polyfill#554

Closed
mathiasbynens wants to merge 1 commit into
google:masterfrom
mathiasbynens:fix-String.prototype.startsWith
Closed

Improve String.prototype.startsWith polyfill#554
mathiasbynens wants to merge 1 commit into
google:masterfrom
mathiasbynens:fix-String.prototype.startsWith

Conversation

@mathiasbynens

Copy link
Copy Markdown
Member

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

Comment thread src/runtime/runtime.js Outdated

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

arv commented Dec 17, 2013

Copy link
Copy Markdown
Contributor

Thanks for taking care of these.

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

@mathiasbynens

Copy link
Copy Markdown
Member Author

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

@arv

arv commented Dec 17, 2013

Copy link
Copy Markdown
Contributor

@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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants