5
With this
of to do this:
function Biscoito(sabor,marca,preco) {
this.sabor = sabor;
this.rodas = marca;
this.preco = preco;
this.mostrarAtributos = function(){
return sabor + ", " + marca + ", " + preco;
}
}
var maizena = new Biscoito("Leite", "Maizena", 1.20);
alert(maizena.mostrarAtributos());
That is, from to define the properties of the prototype DIRECTLY in the instance through the parameters.
But if I want to do the same building the prototype with prototype
? I tried to do it and it didn’t work :(
function Biscoito(sabor, marca, preco) {}
Biscoito.prototype.sabor = sabor;
Biscoito.prototype.marca = marca;
Biscoito.prototype.preco = preco;
Biscoito.prototype.mostrarAtributos = function(){
return sabor + ", " + marca + ", " + preco;
}
var biscoito = new Biscoito("Leite", "Maizena", 1.20);
alert(biscoito.mostrarAtributos());