class variables in javascript code example
Example 1: javascript class
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
get area() {
return this.calcArea();
}
calcArea() {
return this.height * this.width;
}
}
const square = new Rectangle(10, 10);
console.log(square.area);
Example 2: variables in js class
constructor(){
this.foo = bar
}
Example 3: class declaration in javascript
class NameOfClass {
obj="text";
obj2="some other text";
}
console.log(new NameOfClass);
Example 4: how to create class in javascript
class ClassName
{
}