JavaScript Classes: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 11: Line 11:


=Declaration=
=Declaration=
Use the <code>class</code> keyword:
<syntaxhighlight lang='js'>
<syntaxhighlight lang='js'>
class Simplest {
  constructor(content) {
    this.content = content;
  }
}
</syntaxhighlight>
</syntaxhighlight>


=Class Expression=
=Class Expression=

Revision as of 22:45, 21 January 2020

External

Internal

Overview

A JavaScript class is a syntactical superstructure in top of the language's existing prototype-based inheritance, and it does not introduce a new object-oriented inheritance model in JavaScript. A class is a special function, so like in the functions' case, a class syntax has two components: declarations and expressions.

Declaration

Use the class keyword:

class Simplest {
  constructor(content) {
    this.content = content;
  }
}

Class Expression