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 178 views
1 answer 125 views
1 answer 171 views
1 answer 188 views
1 answer 105 views
...