Skip to content

Instantly share code, notes, and snippets.

@fkleuver
Created February 4, 2020 18:28
Show Gist options
  • Select an option

  • Save fkleuver/00b5885ea6c8e87e3a5a7f5c15b57a52 to your computer and use it in GitHub Desktop.

Select an option

Save fkleuver/00b5885ea6c8e87e3a5a7f5c15b57a52 to your computer and use it in GitHub Desktop.
// ES6 class
function testClass(N){
class Foo {
constructor(prop1, prop2) {
this.prop1 = prop1;
this.prop2 = prop2;
}
get getter1() {}
method1() {}
method2() {}
}
for (let i = 0; i < N; ++i){
new Foo(i, null);
}
}
testClass(1e6);
// ES5 prototype
function testClass(N){
function Foo(prop1, prop2) {
this.prop1 = prop1;
this.prop2 = prop2;
}
Foo.prototype.method1 = function () {};
Foo.prototype.method2 = function () {};
Object.defineProperty(Foo.prototype, 'getter1', { get() {}, configurable: true });
for (let i = 0; i < N; ++i){
new Foo(i, null);
}
}
testClass(1e6);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment