【发布时间】:2012-11-16 13:25:50
【问题描述】:
我注意到 Google Chrome 调试器的行为因 JS 对象的创建方式而异;
如果我创建一个这样的 js 对象;
var SonA = function(thename) {
this.firstname = thename || "Graham";
this.age = 31;
}
SonA.prototype = new Father();
然后 Chrome 的调试器不允许我深入查看原型。但是,它确实给了我实例变量名称和年龄的键值对。
但是,如果我省略了 this 关键字,我可以深入到原型,但我不会在调试器中显示实例变量。
//SonB doesn't use this keyword
var SonB = function(thename) {
firstname = thename || "Graham";
age = 31;
}
SonB.prototype = new Father();
console.log(new SonA()); //this logs as: SonA {firstname: "graham", age: 31}
console.log(new SonB()); //this logs as as drill down object that shows the prototype
有谁知道这里发生了什么,为什么调试器的行为不同?下面的图片和 jsfiddle 可能会使问题更清晰易懂;
【问题讨论】:
-
使用
console.dirjsfiddle.net/7z8sp/2
标签: javascript google-chrome-devtools