-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
doc: explain differences in console.assert between node and browsers #6169
Conversation
@nodejs/documentation |
```js | ||
'use strict'; | ||
|
||
const myConsole = Object.setPrototypeOf({ |
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 do we need a setPrototypeOf
call here?
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.
actually, the example is incomplete... just noticed... it should be:
const myConsole = Object.setPrototypeOf({
assert(assertion, message, ...args) {
try {
console.assert(assertion, message, ...args);
} catch (err) {
console.error(err.stack);
}
}
}, console);
Essentially, this creates a simple extension of the existing console object without monkey-patching it.
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.
Fixed the example in updated commit
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.
Not sure we should be encouraging such liberal use of setPrototypeOf. A lot of people have strong feelings against it and it sort of lumped in the language by mistake (it's a funny story really).
If we are using it though, why not just:
const myConsole = { __proto__: console,
assert: ... }
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.
Not sure encouraging use of __proto__
is any better.
Provide an example for implementing browser like behavior for console.assert. This "fixes" nodejs#5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired. Fixes: nodejs#5340
b74e791
to
4c5a6c3
Compare
ping @nodejs/documentation |
@@ -109,6 +109,45 @@ console.assert(false, 'Whoops %s', 'didn\'t work'); | |||
// AssertionError: Whoops didn't work | |||
``` | |||
|
|||
It is important to note that the `console.assert()` method in Node.js is | |||
implemented differently than the `console.assert()` method available in |
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.
perhaps a link to https://developer.mozilla.org/en-US/docs/Web/API/Console
LGTM with a nit. |
A couple links suggested, but LGTM |
@eljefedelrodeodeljefe @techjeffharris ... updated, PTAL! |
Though this PR is only targeting a clarification of console.assert, as log as there's a link to the browser console.assert maybe we should have a link to the general browser console API in the following section: (sorry, not in a place to easily see which line)
Might be more appropriate in another PR...? |
The most recent changes LGTM, regardless. |
LGTM. Thx @jasnell. @techjeffharris let's collect those in the wake of nodejs/docs#100 (?) |
Provide an example for implementing browser like behavior for console.assert. This "fixes" #5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired. Fixes: #5340 PR-URL: #6169 Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Jeff Harris <@techjeffharris>
Landed in 40a5761 |
Provide an example for implementing browser like behavior for console.assert. This "fixes" #5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired. Fixes: #5340 PR-URL: #6169 Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Jeff Harris <@techjeffharris>
Provide an example for implementing browser like behavior for console.assert. This "fixes" #5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired. Fixes: #5340 PR-URL: #6169 Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Jeff Harris <@techjeffharris>
Provide an example for implementing browser like behavior for console.assert. This "fixes" #5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired. Fixes: #5340 PR-URL: #6169 Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Jeff Harris <@techjeffharris>
This definitely NOT fixes #5340. Sad news everyone. |
The way browsers implement |
Thank you. |
Provide an example for implementing browser like behavior for console.assert. This "fixes" #5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired. Fixes: #5340 PR-URL: #6169 Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Jeff Harris <@techjeffharris>
Provide an example for implementing browser like behavior for console.assert. This "fixes" #5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired. Fixes: #5340 PR-URL: #6169 Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Jeff Harris <@techjeffharris>
Provide an example for implementing browser like behavior for console.assert. This "fixes" nodejs#5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired. Fixes: nodejs#5340 PR-URL: nodejs#6169 Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Jeff Harris <@techjeffharris>
Provide an example for implementing browser like behavior for console.assert. This "fixes" #5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired. Fixes: #5340 PR-URL: #6169 Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Jeff Harris <@techjeffharris>
Provide an example for implementing browser like behavior for console.assert. This "fixes" #5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired. Fixes: #5340 PR-URL: #6169 Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Jeff Harris <@techjeffharris>
Provide an example for implementing browser like behavior for console.assert. This "fixes" #5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired. Fixes: #5340 PR-URL: #6169 Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Jeff Harris <@techjeffharris>
Provide an example for implementing browser like behavior for console.assert. This "fixes" #5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired. Fixes: #5340 PR-URL: #6169 Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Jeff Harris <@techjeffharris>
Checklist
Affected core subsystem(s)
doc, console
Description of change
Provide an example for implementing browser like behavior for console.assert.
This "fixes" #5340 by providing an alternative to changing Node.js' implemented behavior. Instead, we document the differences and show how to work around them if browser like semantics are desired.
Fixes: #5340