How to show full object in Chrome console?

前端 未结 9 1301
情话喂你
情话喂你 2020-11-28 02:04
var functor=function(){
    //test
}

functor.prop=1;

console.log(functor);

this only show the function part of the functor, cannot show the prope

9条回答
  •  青春惊慌失措
    2020-11-28 02:24

    I wrote a function to conveniently print things to the console.

    // function for debugging stuff
    function print(...x) {
        console.log(JSON.stringify(x,null,4));
    }
    
    // how to call it
    let obj = { a: 1, b: [2,3] };
    print('hello',123,obj);
    

    will output in console:

    [
        "hello",
        123,
        {
            "a": 1,
            "b": [
                2,
                3
            ]
        }
    ]
    

提交回复
热议问题