1var Class = { 2 create: function() { 3 return function() { //vararg 4 this.initialize.apply(this, arguments); 5 } 6 } 7}; 8 9Color = Class.create(); 10Color.prototype = { 11 red: 0, green: 0, blue: 0, 12 initialize: function(r,g,b) { 13 this.red = r; 14 this.green = g; 15 this.blue = b; 16 } 17} 18 19function bench(x) { 20 var d = new Date; 21 var colors = new Array(16); 22 for (var i=0;i<1e8;i++) { 23 colors[i&0xf] = (new Color(1,2,3)); 24 } 25 print(new Date - d); 26 return colors; 27} 28bench(17); 29 30print("Swapping out call"); 31Function.prototype.call = function() { 32 throw "This should not happen, apply should be called instead"; 33}; 34 35bench(17); 36 37print("All done!"); 38