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

Include information/section on "Method definitions in object literals" #29489

Closed
DanKaplanSES opened this issue Oct 5, 2023 · 3 comments · Fixed by #30947
Closed

Include information/section on "Method definitions in object literals" #29489

DanKaplanSES opened this issue Oct 5, 2023 · 3 comments · Fixed by #30947
Labels
Content:JS JavaScript docs

Comments

@DanKaplanSES
Copy link
Contributor

DanKaplanSES commented Oct 5, 2023

MDN URL

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions

What specific section or headline is this issue about?

Method definitions in classes

What information was incorrect, unhelpful, or incomplete?

From my perspective, this is incomplete:

Public instance methods are defined on the prototype property of the class and are thus shared by all instances of the class. They are writable, non-enumerable, and configurable.

What did you expect to see?

I'm browsing the documentation because I'm trying to learn the difference between these two:

class ClassWithPublicInstanceMethod {
  publicMethod() {
    return "hello world";
  }
}

const objectLiteralMethod = {
  publicMethod() {
    return "hello world";
  }
}

But as far as I can tell, the article only explains this for classes. If it mentions how this works on object literals, none of the following section names imply that. This also seems like the most appropriate article for this information; if it's documented elsewhere, I'm not sure where else to look.

I found some information in another page: Object initializer. It doesn't answer my question, but maybe it could be linked to and/or updated to include the answer instead? I don't prefer the latter: I wouldn't expect the information to be there when there's another article title "Method definitions."

Do you have any supporting links, references, or citations?

n/a

Do you have anything more you want to share?

It might make sense to create a whole new section for this information? This section is called "Method definitions in classes", but I'm looking for information regarding "Method definitions in object literals."

MDN metadata

Page report details
@DanKaplanSES DanKaplanSES added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Oct 5, 2023
@github-actions github-actions bot added the Content:JS JavaScript docs label Oct 5, 2023
@Josh-Cena
Copy link
Member

Josh-Cena commented Oct 5, 2023

This section is the only section discussing method definition in classes; everything else is about object literals (or at least, common features between the two). What information are you looking for exactly?

Method definitions in object literals are too straightforward: foo() {} is exactly equivalent to foo: function () {}, except for the two differences already listed. It doesn't make sense to talk about them in isolation.

@DanKaplanSES
Copy link
Contributor Author

@Josh-Cena

Method definitions in object literals are too straightforward: foo() {} is exactly equivalent to foo: function () {}, except for the two differences already listed. It doesn't make sense to talk about them in isolation.

The article is well written so I understand the two differences between foo() {} and foo: function () {}, but what are the similarities? Specifically, are object literal functions/methods "writable, enumerable, and configurable?" I think, "Yes," but this issue is about documenting it like it's done for class methods.

@Josh-Cena
Copy link
Member

I see. All object properties are equivalent in terms of their attributes, but we can explicitly spell that out.

@Josh-Cena Josh-Cena removed the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:JS JavaScript docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants