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

Replaced hasOwnProperty with hasOwn in code examples #18190

Merged
merged 9 commits into from
Jul 13, 2022
Merged

Replaced hasOwnProperty with hasOwn in code examples #18190

merged 9 commits into from
Jul 13, 2022

Conversation

maurer2
Copy link
Contributor

@maurer2 maurer2 commented Jul 10, 2022

Summary

Hello, I replaced hasOwnProperty with hasOwn as suggested here https://github.com/orgs/mdn/discussions/143 (number 6) in various pages.
I left it in place in en-us/web/javascript/reference/global_objects/object/hasown/index.md and en-us/web/javascript/reference/global_objects/object/hasownproperty/index.md as those pages explicitly mention the differences between the two functions. Some other pages already had examples with both functions so I left them untouched was well.

Motivation

Improves legibility of code samples.

Supporting details

Discussion: https://github.com/orgs/mdn/discussions/143

This PR…

  • Rewrites (or significantly expands) a document

@github-actions github-actions bot added Content:JS JavaScript docs Content:Learn Learning area docs Content:WebAPI Web API docs labels Jul 10, 2022
@maurer2 maurer2 marked this pull request as ready for review July 10, 2022 20:30
@maurer2 maurer2 requested review from a team as code owners July 10, 2022 20:30
@maurer2 maurer2 requested review from sideshowbarker and removed request for a team July 10, 2022 20:30
@maurer2 maurer2 changed the title Replaced hasOwnProperty with hasOwn Replaced hasOwnProperty with hasOwn in code examples Jul 10, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jul 11, 2022

Preview URLs

Flaws

Note! 12 documents with no flaws that don't need to be listed. 🎉

URL: /en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Automated_testing
Title: Introduction to automated testing
on GitHub
Flaw count: 1

  • broken_links:
    • Link points to the page it's already on

URL: /en-US/docs/Web/JavaScript/Guide/Working_with_Objects
Title: Working with objects
on GitHub
Flaw count: 1

  • macros:
    • wrong xref macro used (consider changing which macro you use)

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
Title: Object
on GitHub
Flaw count: 2

  • macros:
    • wrong xref macro used (consider changing which macro you use)
  • bad_bcd_links:
    • no explanation!

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
Title: Object.assign()
on GitHub
Flaw count: 1

  • macros:
    • wrong xref macro used (consider changing which macro you use)

URL: /en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields
Title: Public class fields
on GitHub
Flaw count: 1

  • bad_bcd_links:
    • no explanation!

URL: /en-US/docs/Web/API/HTMLElement/style
Title: HTMLElement.style
on GitHub
Flaw count: 1

  • broken_links:
    • Can't resolve /en-US/docs/Web/CSS/CSS_Properties_Reference

URL: /en-US/docs/Web/API/Media_Streams_API/Constraints
Title: Capabilities, constraints, and settings
on GitHub
Flaw count: 2

  • macros:
    • /en-US/docs/Web/API/MediaTrackCapabilities does not exist
    • /en-US/docs/Web/API/MediaTrackCapabilities does not exist

External URLs

URL: /en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Automated_testing
Title: Introduction to automated testing
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Guide/Indexed_collections
Title: Indexed collections
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Guide/Working_with_Objects
Title: Working with objects
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties
Title: Enumerability and ownership of properties
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Errors/Undefined_prop
Title: ReferenceError: reference to undefined property "x"
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Statements/for...in
Title: for...in
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Statements/var
Title: var
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Statements/for...of
Title: for...of
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
Title: Object
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
Title: Object.assign()
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames
Title: Object.getOwnPropertyNames()
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields
Title: Public class fields
on GitHub

No new external URLs


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

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer
Title: Object initializer
on GitHub

No new external URLs


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

No new external URLs


URL: /en-US/docs/Web/API/HTMLElement/style
Title: HTMLElement.style
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/Media_Streams_API/Constraints
Title: Capabilities, constraints, and settings
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/Web_Workers_API/Using_web_workers
Title: Using Web Workers
on GitHub

No new external URLs


URL: /en-US/docs/Web/API/MediaDevices/getSupportedConstraints
Title: MediaDevices.getSupportedConstraints()
on GitHub

No new external URLs

(this comment was updated 2022-07-13 04:58:06.938455)

@teoli2003
Copy link
Contributor

Thanks a lot! Your PR is very valuable.

Before doing a formal review, thanks to your PR, I raised a question there. I think there is an extra pattern we should fix at the same time.

Once it is settled, we'll move forward with this PR.

@teoli2003 teoli2003 requested review from teoli2003 and removed request for a team and sideshowbarker July 11, 2022 06:11
@@ -95,7 +95,7 @@ operator on a global variable.
```js
'use strict';
var x = 1;
globalThis.hasOwnProperty('x'); // true
Object.hasOwn(globalThis, 'x') // true
Copy link
Contributor

Choose a reason for hiding this comment

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

Missed ; that's present in all the rest code of the example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I fixed it. Although there is some weird orphaned back ticks in main in line 123, which I removed.

Copy link
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.

This looks good. I think there is one case where we can simplify further and get rid of hasOwnProperty/hasOwn, and simplify even more!

@@ -450,7 +450,7 @@ Let's have a brief look at how we'd access the API using Node.js and [node-sauce
myAccount.getJobs(function (err, jobs) {
// Get a list of all your jobs
for (let k in jobs) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we couldn't use for...of here and get one step further in simplifying this to:

          for (const job of jobs) {
            myAccount.showJob(job.id, function (err, res) {
              let str = res.id + ": Status: " + res.status;
              if (res.error) {
                str += "\033[31m Error: " + res.error + " \033[0m";
              }
              console.log(str);
            }
          }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, make sense. Thanks. I implemented the change.

Copy link
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 eb93656 into mdn:main Jul 13, 2022
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:WebAPI Web API docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants