不要将其转换为字符串。
在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
更有信息性。