node js class es6 code example
Example 1: javascript classes
class SayHelloTo {
name (to) {
console.log(`Hello ${to}`);
}
constructor (to) {
this.name(to);
}
}
const helloWorld = new SayHelloTo(World);
Example 2: es6 class example
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
}
Example 3: class declaration in javascript
class NameOfClass {
//class declaration first letter should be capital it's a convention
obj="text";
obj2="some other text";
}
//always call class with "new" key word
console.log(new NameOfClass);