プロトタイプメソッドのメリットはありますか?Javascript:初期メソッドのプロトタイプへの格納
プロトタイプのメソッドを使用せずにオブジェクトの新しいインスタンスを作成すると、その逆の場合より多くのメモリを消費しますか?
共有コンテキストが必要ない場合、一部の開発者がプロトタイプ内に初期メソッドを格納する理由を理解できません。
私は考えている唯一のものは、メモリ使用量です...
// first one
function t(){
this.method1=function(){
};
this.method2=function(){
};
}
// second one
function tt(){
}
tt.prototype={
method1:function(){
}
,method2:function(){
}
}
var storage1=[];
var storage2=[];
var i=0;
while(i<10000) {
storage1.push(new t());
storage2.push(new tt());
i++;
}