Editing Constructors with Array Parameters This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Since I love arrays so much (doesn't everybody?) I wanted to test the fastest way of creating an object from a constructor using an array as parameter values. Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) var arr = [1, 2, 3] function construct(val1, val2, val3) { this.val1 = val1; this.val2 = val2; this.val3 = val3; } function construct2(args) { this.val1 = args[0]; this.val2 = args[1]; this.val3 = args[2]; } function construct3(args) { var num = 1; for (var val = 0; val < args.length; val++) { this['val' + num] = args[val]; ++num; } } function construct4(args) { } construct4.prototype.fn = function(args) { var num = 1; for (var val = 0; val < args.length; val++) { this['val' + num] = args[val]; ++num; } } Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code var _1 = new construct(); construct.apply(_1, arr); Test 2 Title Async (check if this is an asynchronous test) Code var _2 = new construct2(arr); Test 3 Title Async (check if this is an asynchronous test) Code var _3 = new construct3(arr); Test 4 Title Async (check if this is an asynchronous test) Code var _4 = new construct4(); _4.fn(arr);