Я думаю, что вы на самом деле ищете классы, попробуйте сделать это;
var receitas = [];
var ingredientes = [];
class Receita {
constructor(aTipo, aNome, aTempo, aCusto, aDificuldade, aDescricao, aIngredientes) {
this.nome = aNome;
this.tipo = aTipo;
this.tempo = aTempo;
this.custo = aCusto;
this.dificuldade = aDificuldade;
this.descricao = aDescricao;
this.ingredientes = aIngredientes;
}
}
class Ingrediente {
constructor(aNome, aQuantidade) {
this.nome = aNome;
this.quantidade = aQuantidade;
}
}
Итак, чтобы добавить ingrediente
в массив ingredientes
, вы должны сделать что-то вроде этого:
var newReceita = new receita('Bolo', 'Bolo de fubá');
ingredientes = [
new ingrediente('Farinha', 300),
new ingrediente('Ovos', 2)
]
receita.ingredientes = ingredientes;