+ 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?

6th Jan 2019, 10:47 PM
Thomas Czernek
Thomas Czernek - avatar
5 Answers
+ 5
You should use prototype method wherever you could, because of the single prototype method has faster speed and less memory allocation.
7th Jan 2019, 1:40 PM
Calviղ
Calviղ - avatar
+ 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.
7th Jan 2019, 2:34 PM
Calviղ
Calviղ - avatar
+ 1
oh, a little more concept is neede. "prototype"
16th Jan 2019, 5:32 AM
I C
I C - avatar
0
what is this for?
9th Jan 2019, 6:31 PM
Nuh Cetin
Nuh Cetin - avatar
0
Нихуя не понял, но очень интересно
14th Jan 2019, 2:56 PM
Вася Фанта
Вася Фанта - avatar