Replaced hasOwnProperty with hasOwn in code examples#18190
Conversation
|
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. |
| 'use strict'; | ||
| var x = 1; | ||
| globalThis.hasOwnProperty('x'); // true | ||
| Object.hasOwn(globalThis, 'x') // true |
There was a problem hiding this comment.
Missed ; that's present in all the rest code of the example.
There was a problem hiding this comment.
Thanks. I fixed it. Although there is some weird orphaned back ticks in main in line 123, which I removed.
# Conflicts: # files/en-us/web/javascript/reference/statements/var/index.md
teoli2003
left a comment
There was a problem hiding this comment.
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) { | |||
There was a problem hiding this comment.
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);
}
}
There was a problem hiding this comment.
Okay, make sense. Thanks. I implemented the change.
Summary
Hello, I replaced
hasOwnPropertywithhasOwnas 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.mdanden-us/web/javascript/reference/global_objects/object/hasownproperty/index.mdas 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…