Added shorter method definitions in objects for code examples#18370
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
teoli2003
suggested changes
Jul 15, 2022
Contributor
teoli2003
left a comment
There was a problem hiding this comment.
I'm really happy to see this happening.
I have a few typo details, but this is almost good to go.
Thanks a lot!
| > // Satisfies both the Iterator Protocol and Iterable | ||
| > const myIterator = { | ||
| > next: function () { | ||
| > next () { |
Contributor
There was a problem hiding this comment.
Suggested change
| > next () { | |
| > next() { |
| > // ... | ||
| > }, | ||
| > [Symbol.iterator]: function () { | ||
| > [Symbol.iterator] () { |
Contributor
There was a problem hiding this comment.
Suggested change
| > [Symbol.iterator] () { | |
| > [Symbol.iterator]() { |
| return { | ||
| // this is the iterator object, returning a single element (the string "bye") | ||
| next: function () { | ||
| next () { |
Contributor
There was a problem hiding this comment.
Suggested change
| next () { | |
| next() { |
| let nextIndex = 0; | ||
| return { | ||
| next: function () { | ||
| next () { |
Contributor
There was a problem hiding this comment.
Suggested change
| next () { | |
| next() { |
| let index = 0; | ||
| return { | ||
| next: function () { | ||
| next () { |
Contributor
There was a problem hiding this comment.
Suggested change
| next () { | |
| next() { |
Contributor
Author
There was a problem hiding this comment.
Okay, thanks. I fixed the issues, updated the pr with the latest changes from main and restored one of the examples (Changing displayName dynamically in files/en-us/web/javascript/reference/global_objects/function/displayname/index.md) since setting the displayname doesn't seem to work. Example:
const object = {
// anonymous
someMethod(value) {
someMethod.displayName = `someMethod (${value})`;
}
};
console.log(object.someMethod.displayName); // "undefined"
object.someMethod('123')
console.log(object.someMethod.displayName); // "someMethod (123)" --> someMethod is not defined…thand-function # Conflicts: # files/en-us/web/javascript/reference/global_objects/function/displayname/index.md # files/en-us/web/javascript/reference/global_objects/function/name/index.md
Contributor
|
Thank you very much! |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Updated the method definition style in objects using the shorter ES6 syntax as mentioned in section 9 in (https://github.com/orgs/mdn/discussions/143).
Motivation
Shorter syntax is more readable and more widely used nowadays.
Supporting details
[(https://github.com/orgs/mdn/discussions/143)]
Metadata