Which javascript object creation is more efficient? -


i understand recommended manner version 2 (below), using prototype. however, difference between 2 versions because not version 1 beat version 2 in memory consumption, routinely completes in half third of time (according tests using chrome).

version 1:

   var c = function() { console.log("new c"); }     c.f = function(foo) { console.log("function"); }     var = [];    (var = 0; < 100000; i++) {        a.push(new c());    } 

version 2:

   var c = function() { console.log("new c"); }     c.prototype.f = function(foo) { console.log("function"); }     var = [];    (var = 0; < 100000; i++) {        a.push(new c());    } 

version 1 give function object only, while version 2 provide function object function holding prototype.

and i'm pretty curious see if of new c(); instanciations in version 1 has access c.f method...


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -