
Modern JS Talk Classes
This article was originally published on bmf-tech.com . ※This article is a reprint from the Innovator Japan Engineers’ Blog . Class Definition from ECMAScript6 Before ECMAScript6, we used the new operator and prototype property to achieve class-like functionality, but from ECMAScript6, we can define classes using the class keyword. The class keyword is syntactic sugar for class definitions using the new operator and prototype property. There are two ways to define a class using the class keyword: class declarations and class expressions. Example of class definition using class declaration: class Human { constructor ( age , name ) { this . age = age ; this . name = name ; } sayAge () { return this . age ; } sayName () { return this . name ; } } const humanInstance = new Human ( 24 , " Bob " ); console . log ( humanInstance . sayAge ()); // 24 console . log ( humanInstance . sayName ()); // Bob Example of class definition using class expression: const Human = class Human { constructor (
Continue reading on Dev.to JavaScript
Opens in a new tab


