Search⌘ K

Challenge: Solution Review

Explore how to convert traditional JavaScript constructor functions to ES6 class syntax. Learn to define constructors using the constructor keyword and initialize object properties for efficient object creation using creational design patterns.

We'll cover the following...

Solution #

Node.js
class Shape{
constructor(color, sides, name){
this.color = color;
this.sides = sides;
this.name = name;
}
}
var shape = new Shape("blue","4","Square")
console.log(shape)

Explanation

The ES6 version of JavaScript uses classes that are defined using the class keyword to implement the constructor pattern. In this case, the ...