new vs obj literal

Edit on GitHub

new vs. object literal

Setup

function thing(value, metadata) {
   this.value = value;
   this.metadata = metadata;
}

real_value = 123456;
real_metadata = [];

Tests

  • new

    var x = new thing(real_value, real_metadata);
  • obj literal

    var x = {
        value: real_value;
        metadata: real_metadata;
    };