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

Mention String#replaceAll as well as String#replace under Symbol.replace article #32507

Merged
merged 3 commits into from
Mar 1, 2024

Conversation

lionel-rowe
Copy link
Contributor

Description

Mention String#replaceAll as well as String#replace under Symbol.replace article.

Motivation

String#replaceAll also looks up Symbol.replace:

class Replacer {
    [Symbol.replace](str) {
        return `hello, ${str}`
    }
}

console.log('world'.replace(new Replacer()))
// hello, world
console.log('world'.replaceAll(new Replacer()))
// hello, world

Additional details

ES Spec:

c. Let replacer be ? GetMethod(searchValue, @@replace).

MDN's RegExp.prototype[@@replace]() article already mentions this, but not the Symbol.replace one.

Related issues and pull requests

N/A

@lionel-rowe lionel-rowe requested a review from a team as a code owner March 1, 2024 12:15
@lionel-rowe lionel-rowe requested review from Josh-Cena and removed request for a team March 1, 2024 12:15
@github-actions github-actions bot added Content:JS JavaScript docs size/xs [PR only] 0-5 LoC changed labels Mar 1, 2024
Copy link
Contributor

github-actions bot commented Mar 1, 2024

Preview URLs

(comment last updated: 2024-03-01 15:53:09)

@github-actions github-actions bot added size/s [PR only] 6-50 LoC changed and removed size/xs [PR only] 0-5 LoC changed labels Mar 1, 2024
@Josh-Cena Josh-Cena merged commit da480cf into mdn:main Mar 1, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:JS JavaScript docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants