felvieira
2/10/2019 - 5:01 PM

Class in JS 2 with functions

const Calc = function(num1,num2){
this.num1 = num1;
this.num2 = num2;
  return{
    out: () => {
      console.log(this.num1,this.num2)
    }
  }
}
const a = new Calc(1,2);
// Loga 1 2
a.out()
// Loga 1 2
a.out.bind({ num1: 4, num2: 5})()

// OU

const Calc = function(num1,num2){
const soma = num1 + num2
  return{
    out: () => {
      console.log(num1,num2,soma)
    }
  }
}
const a = new Calc(1,2);
a.out();
class Calc {
  constructor(num1,num2){
    this.num1 = num1;
    this.num2 = num2;
  }
  out(){
    console.log(this.num1, this.num2)
  }
}

const a = new Calc(1,2)
// Loga 1 2
a.out()
// Loga 4 5
a.out.bind({ num1: 4, num2: 5})()