Inspired from a SO question I noticed that the snippets code console.logs this
weirdly in the following scenario:
function hello() {
console.log('hello this is', this);
}
hello.call(5);
which prints hello this is {}
In node, this returns: hello this is [Number: 5]
and in chrome, this prints: hello this is Number {5}
What gives?
{}
. I would prefer[Number: 5]
given that Objects are printed with [] in JSconsole.log('hello this is', this.toString())
orconsole.log(```hello this is ${this}```)
instead ofthis
; then you'll get the defaulttoString
implementation (in this case,hello this is 5
). But as @Cerbrus notes, the Stack Snippets code base hasn't been changed since... 2014? No, looks like they at least updated the Tidy code in April. Maybe they can roll in the latest from canon...