Answer the question
In order to leave comments, you need to log in
What is the best way to design objects for memory optimization?
Hi all.
You need to create elements and store them in memory for later construction of html blocks from them.
I see 2 approaches.
First
function inputClass(id)
{
this.id = id;
function log(){
console.log(this.id);
};
this.log = log;
}
id: "first"
log: log()
__proto__: inputClass
function inputClass(id)
{
this.id = id;
}
inputClass.prototype.log = function log(){
console.log(this.id);
};
id: "second"
__proto__: inputClass
Answer the question
In order to leave comments, you need to log in
Do I understand correctly that the more objects, the more we save memory in the second case (through prototype)?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question