-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
util: use Object.create(null) for dictionary object #3791
Changes from all commits
e8091ed
54285ca
c7de80b
c61e8c2
36ee9fe
7fa52db
e412b4f
56995c7
fe4cdc1
ec9f530
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 |
---|---|---|
|
@@ -159,9 +159,9 @@ function stylizeNoColor(str, styleType) { | |
|
||
|
||
function arrayToHash(array) { | ||
var hash = {}; | ||
var hash = Object.create(null); | ||
|
||
array.forEach(function(val, idx) { | ||
array.forEach(function(val) { | ||
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. Would we want to continue to use arrow functions for inline anons? array.forEach(val => hash[val] = true); and/or convert this into a single reduce expression? function arrayToHash(array) {
return array.reduce((acc, val) => {
acc[val] = true;
return acc;
}, Object.create(null));
} 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. Using As for using arrow functions, personally only think they must be used to prevent 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. Ok cool. Yeah I guess I agree, the naming of 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. Ironically @JungMinu has already started some of this :) #3622 Hopefully we'll be able to finish conversion of other applicable cases, but it's not high priority. Don't think the CTC would feel the need to make a stance "official" but if the rest of the code is following some convention then we can point to that as an example going forward. |
||
hash[val] = true; | ||
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. You'd check if |
||
}); | ||
|
||
|
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.
Why not a
Set
instead?