ifo*_*e2d 6 javascript console logging class
我正在尝试使用console.log来调试一些非常简单的Javascript,但它输出的变量值直到console.log调用之后才会更改,此时变量是"类"成员(Chrome 22,Firefox 16).
我期望发生的一个例子是这样的:
var a = 1;
console.log(a);
a += 20;
//console output says a is 1
Run Code Online (Sandbox Code Playgroud)
但如果变量是"类"成员:
var a = new myClass(1);
console.log(a);
a.x += 20;
//console output says a.x is 21
Run Code Online (Sandbox Code Playgroud)
如果控制台没有记录调用日志时存在的值,它何时最终决定记录该值,以及如何解决这个问题!
这里是fwiw的全部代码:
function myClass() {
myClass.myClass.apply(this, arguments);
if (this.constructor === myClass) this.myClass.apply(this, arguments);
};
myClass.myClass = function () {};
myClass.prototype.myClass = function (x_) {
if (x_ === undefined) x_ = 0;
this.x = x_;
}
var a = new myClass(1);
console.log(a);
a.x += 20;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
833 次 |
最近记录: |