0

i want call the function 'ocultarAviso' inside the function 'mostrarAvisoTemporario', but i dont find a way to do this, how i can?

function Aviso(idDaBarraAviso){
    console.log('Funcao aviso criada!');
    this.barra = document.getElementById(idDaBarraAviso);
    this.mostrarAviso = function(mensagemAviso){
        console.log('Mostrar aviso chamado!');
        console.log('Mensagem : ' + mensagemAviso);
        this.barra.style.innerHTML = mensagemAviso;
        this.barra.style.visibility = 'visible';
    }

    this.mostrarAvisoTemporario = function(mensagemAviso, tempoAvisoEmMilis){
        console.log('mostrarAvisoTemporario chamado!');
        console.log('Mensagem : ' + mensagemAviso);
        this.barra.innerHTML = mensagemAviso;
        this.barra.style.visibility = 'visible';
        setTimeout(function(){
            console.log('mostrarAvisoTemporario removendo aviso!');
            //I want call the function here
            this.ocultarAviso(); //how i call? this isn´t working
        }, tempoAvisoEmMilis);
    }

    this.ocultarAviso = function(){
        console.log('OcultarAviso chamado!!');
        this.barra.innerHTML = "";
        this.barra.style.visibility = 'hidden';
    }
}
Thiago Viana
  • 301
  • 2
  • 9
  • 2
    see: [How to access the correct `this` inside a callback?](https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback) – Mark Nov 21 '18 at 00:19
  • 1
    the soluction is only place .bind(this) on the close of the function inside the 'setTimeout', thank you. – Thiago Viana Nov 21 '18 at 00:36

0 Answers0