3

Compared to the actual way of creating "classes" in Javascript as such:

function MyClass(){
}

MyClass.prototype.yada = function(){};

to the new ES6 class

class MyClass {

  yada(){
  }
}

Couldn't find any performance comparisions, but I'm really interested in __proto__/Object.setPrototypeOf inheritance than only the "class sugar" that ES6 offers.

pocesar
  • 6,860
  • 6
  • 56
  • 88
  • 1
    There is no ES6 yet, so it seems a bit early to be asking about performance. And even then, it depends on implementation. Syntax/Language has no performance. Though my understanding is that the ES6 feature is just a syntactic sugar for the classical prototype syntax. – user2736012 Oct 12 '13 at 00:58
  • ES6, ES-Next, Harmony, you name it. I'm just interested in the results ;) – pocesar Oct 12 '13 at 00:59
  • It depends on how classes are finally implemented (if there is any change, though unlikely), and if there are any specification check requirements that may slow down performance of the code. However, I doubt that there is much difference at all. Needless to say, it is up to how both are implemented in ES6-compatible implementations that will really count for performance. – Qantas 94 Heavy Oct 12 '13 at 01:02
  • @SalvadorDali even if it's just a proposal, node 0.11+ can use harmony code, chrome with harmony flag, etc. if the `class` declaration is, behind the scene, compiled to some code that's similar to Coffeescript class, for example, then the performance would be not an issue at all. – pocesar Oct 12 '13 at 01:37

1 Answers1

2

ES6 classes are really just syntactic sugar for constructor functions and prototype initialisations. That is, both versions of your MyClass definition are pretty much equivalent, and will very likely have identical performance characteristics in all implementations (not that there is one yet).

Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72