how to create new class in javascript code example
Example 1: create element javascript with class
// create div element by javascript with class
var div = document.createElement('div');
div.className = "div1";
Example 2: class javascript
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
get area() {
return this.calcArea();
}
calcArea() {
return this.height * this.width;
}
}
const square = new Polygon(10, 10);
console.log(square.area);