Skip to content

Added shorter method definitions in objects for code examples#18370

Merged
teoli2003 merged 4 commits intomdn:mainfrom
maurer2:modernization-shorthand-function
Jul 16, 2022
Merged

Added shorter method definitions in objects for code examples#18370
teoli2003 merged 4 commits intomdn:mainfrom
maurer2:modernization-shorthand-function

Conversation

@maurer2
Copy link
Copy Markdown
Contributor

@maurer2 maurer2 commented Jul 14, 2022

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

  • Adds a new document
  • Rewrites (or significantly expands) a document
  • Fixes a typo, bug, or other error

@github-actions github-actions bot added Content:HTTP HTTP docs Content:JS JavaScript docs Content:Learn Learning area docs Content:Other Any docs not covered by another "Content:" label Content:wasm WebAssembly docs Content:WebAPI Web API docs Content:WebExt WebExtensions docs labels Jul 14, 2022
@github-actions

This comment was marked as resolved.

@github-actions github-actions bot removed the Content:HTTP HTTP docs label Jul 14, 2022
@maurer2 maurer2 marked this pull request as ready for review July 14, 2022 23:28
@maurer2 maurer2 requested review from a team as code owners July 14, 2022 23:28
@maurer2 maurer2 requested review from Rumyra and willdurand and removed request for a team July 14, 2022 23:28
@maurer2 maurer2 changed the title Added short method definition in objects Added shorter method definitions in objects for code examples Jul 14, 2022
Copy link
Copy Markdown
Contributor

@teoli2003 teoli2003 left a comment

Choose a reason for hiding this comment

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

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 () {
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.

Suggested change
> next () {
> next() {

> // ...
> },
> [Symbol.iterator]: function () {
> [Symbol.iterator] () {
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.

Suggested change
> [Symbol.iterator] () {
> [Symbol.iterator]() {

return {
// this is the iterator object, returning a single element (the string "bye")
next: function () {
next () {
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.

Suggested change
next () {
next() {

let nextIndex = 0;
return {
next: function () {
next () {
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.

Suggested change
next () {
next() {

let index = 0;
return {
next: function () {
next () {
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.

Suggested change
next () {
next() {

Copy link
Copy Markdown
Contributor Author

@maurer2 maurer2 Jul 15, 2022

Choose a reason for hiding this comment

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

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

maurer2 added 2 commits July 15, 2022 21:24
…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
Copy link
Copy Markdown
Contributor

@teoli2003 teoli2003 left a comment

Choose a reason for hiding this comment

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

👍

@teoli2003 teoli2003 merged commit d4b12e2 into mdn:main Jul 16, 2022
@teoli2003
Copy link
Copy Markdown
Contributor

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:JS JavaScript docs Content:Learn Learning area docs Content:Other Any docs not covered by another "Content:" label Content:wasm WebAssembly docs Content:WebAPI Web API docs Content:WebExt WebExtensions docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants