+ 4
How do you know when you have too many methods on the prototype/constructor and how can you plan to use a fair amount of each?
When using methods in a constructor, you use more memory because every time an object is created the method is redeclared. An alternative is to declare the methods on the prototype which saves memory but reduces speed because you must go up the prototype chain. Methods on the constructor work best when working with local variables in the constructor and with low instances of objects. Methods on the prototype work best when many objects are being created. How can you plan to use a sufficient amount of each?
5 Answers
+ 5
You should use prototype method wherever you could, because of the single prototype method has faster speed and less memory allocation.
+ 5
I just built the test. Check it out here.
https://code.sololearn.com/WefJpM6Dr6RW/?ref=app
The test concluded that prototype method is faster.
+ 1
oh, a little more concept is neede.
"prototype"
0
what is this for?
0
Нихуя не понял, но очень интересно