node js create class code example
Example 1: create element javascript with class
var div = document.createElement('div');
div.className = "div1";
Example 2: node js class
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
Rectangle.count++;
}
get area() {
return this.calcArea();
}
calcArea() {
return this.height * this.width;
}
static calcArea(width, height) {
return width * height;
}
}
Rectangle.count = 0;
const square = new Rectangle(10, 10);
console.log(square.height, square.width);
console.log(square.area);
console.log(square.calcArea());
console.log(Rectangle.count);
console.log(Rectangle.calcArea(15, 15));
Example 3: js create element with class
var element =document.createElement("span");
element.className = "aClassName";
Example 4: class declaration in javascript
class NameOfClass {
obj="text";
obj2="some other text";
}
console.log(new NameOfClass);