我如何在Chrome工具中看到[object object]所指的内容

How do I see what [object Object] refers to in Chrome Tools?

本文关键字:object Chrome 工具      更新时间:2023-09-26

在chrome工具中,如何查看[OOBJECT OBJECT]表示的内容?测试关键字"this"的函数上下文

 var Calculator = function (eq) {
            // private members...
            var eqCtl = document.getElementById(eq),
                foo = function () { };
            return {
                add: function (x, y) {
                    var val = x + y;
                    eqCtl.innerHTML = val;
                },
                print: function () {
                    console.log("print:  this" + this);
                    this.test(this);
                },
                test: function (obj) {
                    console.log("test: this " + this);
                    console.log("this: obj" + obj);
                }

            }
        };
不要将其转换为字符串。console.log()单独使用:
console.log("test: this ", this);
console.log("test: obj ", obj);

将多个参数传递给console.log方法

console.log("this: obj", obj);

请改用console.dir。在某些情况下,它应该比console.log更有信息性。