javascript - How does setTimeout(console.log.bind(console, "something")) work? -
after reading how hide source of log messages in console? , i'm confused how command works.
i try not use settimeout wrap it, console log show source of log messages. try see stack trace, shows nothing second line:
what settimeout(console.log.bind(console, "something"))
do? , seems cannnot remove settimeout?
is there other way same thing?
let's take piece-by-piece:
what
console.log.bind(console, "something")
?the
function#bind
function creates new function that, when called, call original function using first argumentthis
call , passing along further arguments.console.log.bind(console, "something")
creates (but doesn't call) function that, when is called, callconsole.log
this
setconsole
, passing along"something"
first argument.what
settimeout(x, y)
?it schedules function
x
called aftery
milliseconds browser; if don't supplyy
, defaults0
(call immediately, current code completes).
so taken together, settimeout(console.log.bind(console, "something"))
schedules call console.log
after brief delay.
using delay means call console.log
doesn't happen directly code that; browser calls console.log
directly, not within code. consequently, stack trace doesn't show happened in code, because didn't.
Comments
Post a Comment