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: enter image description here

what settimeout(console.log.bind(console, "something")) do? , seems cannnot remove settimeout?

is there other way same thing?

let's take piece-by-piece:

  1. what console.log.bind(console, "something")?

    the function#bind function creates new function that, when called, call original function using first argument this call , passing along further arguments. console.log.bind(console, "something") creates (but doesn't call) function that, when is called, call console.log this set console , passing along "something" first argument.

  2. what settimeout(x, y)?

    it schedules function x called after y milliseconds browser; if don't supply y, defaults 0 (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

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -