-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Editorial: Tweak EnumerateObjectProperties informative definition #656
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16171,20 +16171,19 @@ <h1>EnumerateObjectProperties (_O_)</h1> | |
<p>The following is an informative definition of an ECMAScript generator function that conforms to these rules:</p> | ||
<pre><code class="javascript"> | ||
function* EnumerateObjectProperties(obj) { | ||
let visited = new Set; | ||
for (let key of Reflect.ownKeys(obj)) { | ||
if (typeof key === "string") { | ||
let desc = Reflect.getOwnPropertyDescriptor(obj, key); | ||
if (desc && !visited.has(key)) { | ||
visited.add(key); | ||
if (desc.enumerable) yield key; | ||
} | ||
const visited = new Set(); | ||
for (const key of Reflect.ownKeys(obj)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's no tweak here. This change is not necessary at all and for consistency it is better to remain without change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @leobalter, thanks for the review. Is it 46b569d or f1883f5 that should be dropped? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just part of TC39, @bterlson is the one able to answer that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's ok to change it to use const, since it's never reassigned. I'd also want to see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am fine with this change. I don't see why this change isn't consistent though - @leobalter can you clarify? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer this example being consistent (the same) along the new releases.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do enforce a particular use in the spec at least - whatever I feel like 😈 My feelings may change (I have in fact become far less likely to use const) but for now I think this helps and I promise I won't change it back to let any time soon. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if (typeof key === "symbol") continue; | ||
const desc = Reflect.getOwnPropertyDescriptor(obj, key); | ||
if (desc && !visited.has(key)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? it just makes the code in spec.html less readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. @shvaikalesh See https://mathiasbynens.be/notes/ambiguous-ampersands for more info on why this is perfectly valid. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mathiasbynens, thanks for the article. I dropped this commit and will make another PR to unescape all unambiguous ampersands in |
||
visited.add(key); | ||
if (desc.enumerable) yield key; | ||
} | ||
} | ||
let proto = Reflect.getPrototypeOf(obj) | ||
const proto = Reflect.getPrototypeOf(obj); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any JavaScript code contains opinionated parts: this function will be just fine without semicolons and strict equals. Does TC39 advise against There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TC39 isn't advising one over the other in either case. Since both are equivalent, and the community tends to prefer const here, I think that's the better choice. |
||
if (proto === null) return; | ||
for (let protoName of EnumerateObjectProperties(proto)) { | ||
if (!visited.has(protoName)) yield protoName; | ||
for (const protoKey of EnumerateObjectProperties(proto)) { | ||
if (!visited.has(protoKey)) yield protoKey; | ||
} | ||
} | ||
</code></pre> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn’t we use
const
overlet
throughout this code sample? None of thelet
s are reassigned.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is mostly a matter of code style. Some might argue that
const
s are for declarations that will never ever be reassigned, like number constants orrequire
s. Andlet
s are for any other declarations: this keeps diffs cleaner.Lets make them
const
s to reflect how most people write ES201* these days.