dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.19k stars 1.57k forks source link

dart:html: Console.log() and its family accept only one argument #19977

Open yutak opened 10 years ago

yutak commented 10 years ago

With JS, I can write something like:

    window.console.log('Debug: ', window, document);

This pretty-prints objects passed in the argument list (instead of toString()'ed ones).

See https://developer.mozilla.org/en/docs/Web/API/console

The counterpart of Dart, however, only accepts just one Object, and thus I can't write equivalent code in Dart.

https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-dom-html.Console

anders-sandholm commented 10 years ago

Added Area-Library, Library-Html, Triaged labels.

alan-knight commented 9 years ago

I don't understand what's being asked for that can't be done with string interpolation.

   window.console.log(' Debug: $window $document');

It refers to pretty-printing the objects, which from the MDN docs seems like it means printing them as a map in JS. But Dart objects don't have that representation, and just being able to produce it adds runtime overhead that I don't think we'd want to do.


Removed Type-Defect label. Added Type-Enhancement, NeedsInfo labels.

yutak commented 9 years ago

For example, type "console.log(document, document, document)" in Chrome's JavaScript console. You will see three #documents that can be clicked to open, so you can browse the content of the document tree inside the developer console. This can't be done with string interpolation.

alan-knight commented 9 years ago

Thanks, that makes sense.


Added Accepted label.

luaVolk commented 5 years ago

Any word on this? This is also important to print text with CSS styles.

For example in JS i can do: In Dart the only way I have to do this is to call the method from JS with dart:js.