0

Classes are introduced to Javascript with ES2015 specification. Are classes expected to work inter-operably with prototypes or can the javascript implementor chose to write it in a completely different way which doesn't work with prototypes? for ex: does member function needs to be a set in prototype of the class object.

Aditya
  • 771
  • 5
  • 11
  • It is hard to answer this question with anything other than a generic "Yes". Is there anything in particular you are concerned about? `class` is just syntax. The values produces could just as well be produced using non-`class` prototype logic. – loganfsmyth Aug 19 '19 at 14:03
  • 1
    [are es6 classes just syntactic sugar for the prototypal pattern in javascript?](https://stackoverflow.com/questions/36419713) – adiga Aug 19 '19 at 14:08

1 Answers1

1

Yes, the ECMAScript specification clearly dictates how a class definition should be evaluated, namely that a new function object is created and that the methods become properties of that function's prototype value. The spec goes in much more detail of course, which can be found here: https://www.ecma-international.org/ecma-262/9.0/#sec-runtime-semantics-classdefinitionevaluation

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143