我在 JavaScript 中有一个这样的构造函数:
function Foo() {
var privateProperty = "goodbye";
this.publicProperty = "hello";
function privateMethod() {
return "Shhhhh";
}
this.publicMethod = function publicMethod() {
return "extroverted";
};
}
Foo.prototype.youCanSeeMe = "I'm out here";
Foo.prototype.typical = function typical() {
return "look at me out here";
};
var b = new Foo();
var c = new Foo();
在最新版本的 v8 JavaScript 引擎中,我的类的哪些属性被复制到内存中?我的意思是,现在内存中有两个副本privateProperty
, publicProperty
, privateMethod
, 等等吗?
如果 的内存占用b
是 100 字节,那么 和 的内存占用b
总共c
是 200 字节吗?更大,更小?