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#bindfunction creates new function that, when called, call original function using first argumentthiscall , passing along further arguments.console.log.bind(console, "something")creates (but doesn't call) function that, when is called, callconsole.logthissetconsole, passing along"something"first argument.what
settimeout(x, y)?it schedules function
xcalled afterymilliseconds 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