带有原型的隐藏类

时间:2015-08-05 13:33:09

标签: javascript performance v8

说我有代码,

function Test() {
    this.a = true;
}
Test.prototype.b = false;

var test = new Test();

如果我这样做,

test.b = true;

这会改变隐藏的类吗?

然后,如果您认为您可能会在对象中添加一些属性,那么在原型中添加初始化为undefined的属性会更高效吗?

function MaybeHasTest() {}
MaybeHasTest.prototype.test = undefined;

var test1 = new MaybeHasTest();
var test2 = new MaybeHasTest();
test2.test = 5; // Is the hidden class kept here?

0 个答案:

没有答案