Question about classes in javascript

0

Hello, I do not understand Invoice that is exactly ... I know that it is a template for all others that I can create with new, but Invoice itself is a object or a function with constructor method, get and set, because if I do console.log tell me it's a function and not an object

class Factura{ 
  constructor(numero, cliente, importe, IVA){
    this._numero = numero;
    this._cliente = cliente;
    this._importe = importe;
    this._IVA = IVA;
  }

  get total(){ 
    return this._cliente;
  }
}
    
asked by francisco dwq 12.01.2018 в 21:27
source

1 answer

0

What you have in your code is neither a function nor a object , it is a class and you have to understand the difference very well .

  • A method is a function and is where you put some code to perform a specific task

  • An object is the instance of the class, that is, the variable with which you call the class

-A class like you said is a template which has certain methods that different objects have in common

Example:

class Perro{ 
  constructor(raza, peso, altura){
    this._raza = raza;
    this._peso = peso;
    this._altura = altura;
  }

  function ladrar(){
    console.log("LADRIDO");
  }
}

.-.-.-.

Function perrera(){
 Animal labrador = new Animal('labrador',50,1.5);
 Animal chihuahua = new Animal('chihuahua',15,1);

labrador.ladrar();
chihuahua.ladrar();
}
    
answered by 13.01.2018 в 00:35