What is the difference between Prototype and an Object?

5

I use new to create objects in javascript and so I noticed quite superficially there is not a big difference between instance with new and using prototype.

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

    
asked by anonymous 19.12.2017 / 00:40

1 answer

6

Object in JavaScript inherits 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 here

    
19.12.2017 / 12:52