我注意到冻结构造函数的原型有副作用,基本上破坏了构造函数链接:
function A(x) {
this.x=x;
}
function B(x, y) {
A.call(this, x);
this.y=y;
}
B.prototype = new A();
Object.freeze(B.prototype);
b=new B(1,2)
// I expected b.x to be 1 here but it's undefined
Run Code Online (Sandbox Code Playgroud)
这是一个演示问题的小提琴:
http://jsfiddle.net/jhpxv20b/2/
有没有一个很好的理由为什么bx最终未定义?
如果这不是一个bug,那么x2如何在小提琴中是1?