How can I make console.log show the current state of an object?

前端 未结 11 1788
走了就别回头了
走了就别回头了 2020-11-22 00:28

In Safari with no add-ons (and actually most other browsers), console.log will show the object at the last state of execution, not at the state when conso

11条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 01:10

    I may be shot for suggesting this, but this can be taken one step further. We can directly extend the console object itself to make it more clear.

    console.logObject = function(o) {
      (JSON.stringify(o));
    }
    

    I don't know if this will cause some type of library collision/nuclear meltdown/rip in the spacetime continuum. But it works beautifully in my qUnit tests. :)

提交回复
热议问题