Thursday, November 4, 2021

JAVASCRIPT - How to work with classes and instances

Base class:
class Shape {
   
  desc = "";

  constructor( _desc ) {
    this.desc = _desc;
  }

  get2Desc() {
    return this.desc + this.desc;
  }

}
Instance of class and calling class method:
b.addEventListener( 'click', function () {    
      
  const myShape = new Shape( "this is a desc" );
  console.log( myShape.get2Desc() );
  
}
Output:
this is a descthis is a desc

No comments:

Post a Comment