-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
http,https: add default argument for Agent.prototype.getName #41906
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
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -217,7 +217,7 @@ Agent.defaultMaxSockets = Infinity; | |||||||||
Agent.prototype.createConnection = net.createConnection; | ||||||||||
|
||||||||||
// Get the key for a given set of request options | ||||||||||
Agent.prototype.getName = function getName(options) { | ||||||||||
Agent.prototype.getName = function getName(options = {}) { | ||||||||||
let name = options.host || 'localhost'; | ||||||||||
Comment on lines
+220
to
221
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'd prefer if instead of creating a throw away object, we used optional chaining and set/keep the default value to
Suggested 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. The 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.
Depends what you mean by simplify, it's a smaller change in term of source code changes, but it's not simpler for end users. Using a throw away objects also has side effects which could be surprising for them: // In userland:
Object.prototype.host = 'something unrelated';
// In core:
function getName(options = {}) { return options.host || 'localhost'; }
console.log(getName()); // 'something unrelated' // In userland:
Object.prototype.host = 'something unrelated';
// In core:
function getName(options = undefined) { return options?.host || 'localhost'; }
console.log(getName()); // 'localhost' My opinion is that Node.js core modules should use optional chaining over creating a throw away objects, it's not a blocking concern by any mean though. Feel free to disagree, the PR is fine as is. 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. Thanks for your detailed explanation. But I have seen many default arguments in nodejs is using empty object, I think we can draft another PR to fix it, if it is necessary. :) |
||||||||||
|
||||||||||
name += ':'; | ||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.