What difference between Prototype and an Object?



  • I use new to create objects in javascript and from what I noticed very superficially there is no big difference between installing with new and using the prototype.

    What is the difference and what advantage in using the prototype?



  • Object in JavaScript inherit the properties and methods of your Prototype.

    This is Prototype:

    function Pessoa(nome, idade) {
        this.nome = nome;
        this.idade = idade;
    }
    

    This is Object:

    var objeto = new Person("Hudson", "26");
    console.log(objeto.nome);
    

    Advantage is the same as in Object Oriented, you can read this article http://dev.rbtech.info/vantagens-de-programar-com-orientacao-a-objetos-oop/


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2