method definition with or without “prototype”

JavaScript performance comparison

Test case created by Jean-Philippe Martin

Info

check if performance is affected by using prototype, instead of this, to define a function

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
method defined with this
function Person(gender) {
  this.gender = gender;

  function myMethod() {
    this.gender = 'x';
  }
  this.method = myMethod;
}
var x = new Person('a');
x.method;
pending…
method defined by prototype
function Person(gender) {
  this.gender = gender;
}
Person.prototype.method2 = function() {
  this.gender = 'x';
};
var x = new Person('a');
x.method2;
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment