1
resposta

erro

estou obtendo esse erro:

insira seu código aqui

LisaNegociacao.js:12 Uncaught TypeError: Function.prototype.apply was called on undefined, which is a undefined and not a function at ListaNegociacao.acionaLista (ListaNegociacao.js:12) at NegociacaoController.aciona (NegociacaoController.js:41) at HTMLFormElement.onsubmit (index.html:17)

class NegociacaoView{

    constructor(tag){

        this.tag = tag;

    }
    _template(model){

        return ` <table class=" table table-hover table-bordered">
        <thead>
            <tr>
                <th class="text-center">DATA</th>
                <th class="text-center">QUANTIDADE</th>
                <th class="text-center">VALOR</th>
                <th class="text-center">VOLUME</th>
            </tr>
        </thead>

        <tbody>
             ${model.lista.map(e=>`

             <tr>

             <td>${DataHelper.dataParaTexto(e.data)}</td>
             <td>${e.quantidade}</td>
             <td>${e.valor}</td>
             <td>${e.obterVolume()}<td>

             </tr>
             ` 

             ).join('')}

        </tbody>

        <tfoot>
            <td colspan="3"></td>
            <td>${model.lista.reduce((total,atual)=>total+atual.obterVolume(),0.0)}</td>
        </tfoot>
    </table>`
    }


    criarTabelaNegociacao(model){
        this.tag.innerHTML = this._template(model);
    }

}

insira seu código aqui

class NegociacaoController{

    constructor(){
        let $ = document.querySelector.bind(document);
        this.data = $("#data");
        this.quantidade =$("#quantidade");
        this.valor = $("#valor");
        this.nView = new NegociacaoView($("#negociacao"));
        this.listaN = new ListaNegociacao(),this,function(model){
            this.nView.criarTabelaNegociacao(model)
        };
        this.nView.criarTabelaNegociacao(this.listaN)
        this.mensagem = new Mensagem();
        this.nView.criarTabelaNegociacao(this.listaN)
        this.msgView = new Mensagemview($("#msg"));

    }

    aciona(event){

        event.preventDefault();

        let data = this.data.value.split("-");
        let dia = data[0];
        let mes = data[1]-1;
        let ano = data[2];

        let d = new Date(dia,mes,ano);
        console.log(d);

        let neg = new Negociacao(
            DataHelper.textoParaData(this.data.value),
            this.quantidade.value,
            this.valor.value

        )

        console.log(neg._data);
        this.mensagem.msg = "negociacao aprovada";
        this.msgView._gerarMsg(this.mensagem);
        this.listaN.acionaLista(neg);
    }

    apagar(){
        this.listaN.apagaLista();
    }
}
class ListaNegociacao{

    constructor(contexto,fun){
        this.listaNegoc = [];
        this.con = contexto;
        this.fun = fun
    }


    acionaLista(negociacao){
        this.listaNegoc.push(negociacao);
        Reflect.apply(this.fun,this.con,[this]);
    }

    apagaLista(){
        this.listaNegoc = [];
        Reflect.apply(this.fun,this.con,[this])
    }

    get lista(){
        return [].concat(this.listaNegoc);
    }

}

o meu esta um pouco diferente mas estava funcionando, quero entender o motivo desse erro

1 resposta

Oi, Luan, tudo bem?

O seu erro LisaNegociacao.js:12 Uncaught TypeError: Function.prototype.apply was called on undefined eu obeservei talvez a falta da letra t* em *LisaNegociacoes. Observa se é realmente isso e nos diz se corrigiu :}

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software