Object literals / JSON typed directly in web console do not output as expected
Categories
(DevTools :: Console, enhancement, P3)
Tracking
(Not tracked)
People
(Reporter: bgrins, Unassigned)
References
(Blocks 1 open bug, )
Details
Attachments
(1 file)
Comment 1•11 years ago
|
||
Comment 2•11 years ago
|
||
Comment 3•11 years ago
|
||
Reporter | ||
Comment 4•9 years ago
|
||
Reporter | ||
Updated•9 years ago
|
Comment 5•8 years ago
|
||
Comment 6•8 years ago
|
||
Reporter | ||
Comment 7•8 years ago
|
||
Comment 8•8 years ago
|
||
Comment 10•7 years ago
|
||
Updated•7 years ago
|
Updated•6 years ago
|
Comment 11•6 years ago
|
||
Comment 12•6 years ago
|
||
If this is done, make sure to do it properly. Initially, Chrome returned an object for {a:1}),({b:2}
instead of a SyntaxError.
However, I agree with Jason Orendorff in bug 1264308 comment #6:
This is a longstanding JS wart and I think it's a mistake to try to paper over it. Making a clean spot in one place just makes the rest of the language look shoddy and inconsistent:
$ node > {}+{} '[object Object][object Object]' > eval("{}+{}") NaN
Comment 13•6 years ago
|
||
The main use case this would support is that users can just post JSON and have it properly expanded. Both Chrome DevTools and Node's REPL allow executing {}
and pretty prints the result. As second mover, we can avoid prior mistakes and get this right the first time with much smaller investment.
where the [Learn more] part is a link taking you to an MDN page explaining what happened and why.
This makes some sense, but maybe we can identify the problem this solves. Users expect the execution to just work, are we trying to teach them to wrap objects with ()? This would inform what kind of material we need to create.
Comment 14•6 years ago
|
||
(In reply to :Harald Kirschner :digitarald from comment #13)
This makes some sense, but maybe we can identify the problem this solves. Users expect the execution to just work, are we trying to teach them to wrap objects with ()? This would inform what kind of material we need to create.
Not to wrap object in parens, since we would support it from the console, but tell them what are code blocks?
Updated•2 years ago
|
Comment 22•9 months ago
|
||
I like the minimalistic way chrome does it
if we modify the input post factum it can make it uncomfortable to copy the input with a triple click -> command+C since it would also highlight the ()
. I like to do it instead of the context menu's "Copy object". there might be a way to keep the copying easy and still display the braces around. and if there isn't one we could create it
Another way to be informative could be adding an info message in between the input and the result, but it'll feel less smooth perhaps and verbose. maybe just do it once? Like a feature onboarding
i'd like to implement the feature, i'll borrow the checks the chrome console does
Comment 23•9 months ago
|
||
I wouldn't call Chrome minimalistic. The minimalistic way is following the language and treat the curly brackets as a block, instead of automagically adding parenthesis to produce an object initializer.
Comment 24•9 months ago
|
||
(In reply to Oriol Brufau [:Oriol] from comment #23)
I wouldn't call Chrome minimalistic.
Hi, i meant minimalistic as opposed to explaining the user the whys and the hows, as Nicolas suggested :)
Just leaving the behaviour as is would be indeed the most minimalistic option, but I really like the feature as it would make using the console more comfortable for many people. In a sense, it's like the top-level await feature, which also automagically wraps the expressions that have await in an an async IIFE
Comment 25•9 months ago
|
||
Updated•9 months ago
|
Comment 27•6 months ago
•
|
||
Another variant of this is the expression {...1}
. In Chrome,Safari and Node it logs {}
, in Firefox, it logs a SyntaxError
.
It seems the console is not a properly implemented JavaScript REPL, at least when it comes to object literals.
Comment 28•29 days ago
|
||
The bug assignee is inactive on Bugzilla, so the assignee is being reset.
Description
•