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?
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?
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