When I assign console.log
to a variable in node.js it works fine,
var l = console.log
l(1) # outputs 1
However, if I do the same thing in Chromium 30's dev tools,
var l = console.log
l(1) # TypeError: Illegal invocation
How come it doesn't work in Chromium's dev tools? Why am I getting,
TypeError: Illegal invocation
If you want to do this to an object that has been already logged (one time thing), chrome console offers a good solution. Hover over the printed object in the console, right click, then click on "Store as Global Variable". Chrome will assign it to a temporary var name for you which you can use in the console.
The console.log() is a function in JavaScript that is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user. Syntax: console.log(" ");
log() function from console class of Node. js is used to display the messages on the console. It prints to stdout with newline. Parameter: This function contains multiple parameters which are to be printed.
As stderr is always written to synchronously, therefore in node. js any use of console. error, or other functions that write to stderr, will block your process until the output has all been written. The method is useful for error messages, but excessive use could slow down your process.
Exactly why this requirement is in place, I don't know, but I guess Chrome's console.log
requires the value of this
to be console
. If you want to store it in a variable, you'll have to bind the value of this
:
var l = console.log.bind(console);
Node.js console does console.log = console.log.bind(this)
in constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With