Constructor Function

FatimaAlam1234 - Dec 2 '23 - - Dev Community
function sum(a, b){
  this.a = a;
  this.b = b;
  this.print = function getSum(){
    return this.a+this.b;
  }
  this.print2 = () => {
    return this.a+this.b;
  }
}

let Sum = new sum(2, 3);
console.log(Sum.print());
console.log(Sum.print2());
Enter fullscreen mode Exit fullscreen mode

The function sum is a constructor function

Output ->
5
VM50 a.js:1 undefined
m=_b,_tp:242 [Violation] 'setTimeout' handler took 66ms

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .