Let's take it piece-by-piece:
What is console.log.bind(console, "something")
?
The Function#bind
function creates a new function that, when called, will call the original function using the first argument as this
for the call and passing along any further arguments. So console.log.bind(console, "something")
creates (but doesn't call) a function that, when it is called, will call console.log
with this
set to console
and passing along "something"
as the first argument.
What is setTimeout(x, y)
?
It schedules the function x
to be called after y
milliseconds by the browser; if you don't supply y
, it defaults to 0
(call back immediately, as soon as the current code completes).
So taken together, setTimeout(console.log.bind(console, "something"))
schedules a call to console.log
after a brief delay.
Using the delay means that the call to console.log
doesn't happen directly from the code where you do that; the browser calls console.log
directly, not within your code. Consequently, the stack trace doesn't show that it happened in your code, because it didn't.