Typically, when I want to display some results from an observable, my process usually looks like this.
const source = interval(3000);
const transform = source.pipe(scan((acc, num) => [...acc, num], []));
transform.subscribe(res => console.log("%c" + res, "color:orange;"));
However, today I discovered that I can simply pass console.log
directly into the observable like so.
const source = interval(3000);
const transform = source.pipe(scan((acc, num) => [...acc, num], []));
transform.subscribe(console.log);
I find this method quite clever and efficient. Yet, I have encountered a challenge in passing additional parameters to style the output of the console log, sparking thoughts as to whether what I'm actually passing in is different from the traditional console.log()
. (Attempting to pass parameters into subscribe()
directly resulted in an error.) After searching for explanations online, I found only tutorials on logging without diving deeper into alternative methods or reasons against it.
Is there a way to include extra parameters in console.log
while using the syntax shown in the second example above? If affirmative, how could this be achieved? And if not, what are the constraints preventing it?
Feel free to experiment with this concept using the following Blitzy link.