Skip to content

Fix multiple issues with new operator page; add example with classes #16608

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

Merged
merged 2 commits into from
May 24, 2022

Conversation

Josh-Cena
Copy link
Member

Summary

Motivation

  1. I noticed some content duplication; they are now deduplicated.
  2. In places we are confusing constructor.prototype and instance.__proto__, I've made the wording less ambiguous.
  3. I've added an example with classes; ideally this entire section should be more biased towards classes nowadays...

Supporting details

Related issues

Metadata

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

@Josh-Cena Josh-Cena requested a review from a team as a code owner May 23, 2022 16:04
@Josh-Cena Josh-Cena requested review from Rumyra and removed request for a team May 23, 2022 16:04
@github-actions github-actions bot added the Content:JS JavaScript docs label May 23, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 23, 2022

Preview URLs

Flaws

None! 🎉

External URLs

URL: /en-US/docs/Web/JavaScript/Reference/Operators/new
Title: new operator
on GitHub

No new external URLs

(this comment was updated 2022-05-24 03:53:52.971155)

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

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

This looks great to me. I had some pretty small suggestions.

ideally this entire section should be more biased towards classes nowadays...

Yes, agreed.

Comment on lines +67 to +69
You can always add a property to a previously defined object instance. For example, the statement `car1.color = "black"` adds a property `color` to `car1`, and assigns it a value of `"black"`.

However, this does not affect any other objects. To add the new property to all objects of the same type, you must add the property to the constructor's `prototype` property. This defines a property that is shared by all objects created with that function, rather than by just one instance of the object type. The following code adds a `color` property with value `"original color"` to all objects of type `Car`, and then overwrites that value with the string `"black"` only in the instance object `car1`. For more information, see [prototype](/en-US/docs/Learn/JavaScript/Objects/Object_prototypes).
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does seem a bit off-topic for this page, but not sure it is worth doing anything about now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right... We mention prototypes and constructor functions in a lot of places, some of which are phrased in a confusing way (e.g. #16290), others could be biased towards classes, but cleaning them up is a bit intractable.

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

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

Thanks for the update @Josh-Cena !

@wbamberg wbamberg merged commit eb033ab into mdn:main May 24, 2022
@Josh-Cena Josh-Cena deleted the fix-new branch May 24, 2022 04:16
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 this pull request may close these issues.

2 participants