I understand the recommended manner is Version 2 (below), using prototype. However, what is the difference between the two versions because not only does Version 1 sometimes beat Version 2 in memory consumption, it also routinely completes in half to a third of the time (according to my tests using Chrome).
Version 1:
var C = function() { console.log("new C"); }
C.f = function(foo) { console.log("function"); }
var a = [];
for (var i = 0; i < 100000; i++) {
a.push(new C());
}
Version 2:
var C = function() { console.log("new C"); }
C.prototype.f = function(foo) { console.log("function"); }
var a = [];
for (var i = 0; i < 100000; i++) {
a.push(new C());
}

fis a property of the constructor functionC, that means the instances you create withnew C()do not have a reference tof. In the second one, you assignftoC's prototype, from which all instances inherit. You are comparing apples with oranges. It should not make a difference in the performance though... here is a jsPerf testcase: jsperf.com/static-vs-prototype