How to define a class with constructor in JavaScript

2 Answers

0 votes
const Test = class {
  constructor(a, b) {
    this.a = a;
    this.b = b;
  }
  mul() {
    return this.a * this.b;
  }
};

console.log(new Test(8, 12).mul());


  
/*
run:
  
96
  
*/

 



answered Nov 18, 2020 by avibootz
0 votes
const Test = class {
  constructor(a, b) {
    this.a = a;
    this.b = b;
  }
  mul() {
    return this.a * this.b;
  }
};
 
const obj = new Test(8, 12);

console.log(obj.mul());
 
 
   
/*
run:
   
96
   
*/

 



answered Nov 18, 2020 by avibootz

Related questions

1 answer 215 views
1 answer 144 views
1 answer 197 views
1 answer 212 views
1 answer 132 views
...