Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
How to change the context of this inside object

I want to access a function which is outside my base object, but if we console.log(this) inside loadAll function then it will give the context inside object. If I console.log(this) any normal function i.e without action or getter/setters it will give context of whole class which I want to achieve

base = observable({
         isDeleting: false,
         registry: observable.map(),
         get all() {
            return this.registry.values();
          },
         loadAll:action.bound(function () {
            console.log(this);
            this.request()
         }),
       });
request = () => { 
console.log('hello');
}

In The above example this will throw an error because it can't access the request function but I wan to find a way to access it.

base = observable({
             isDeleting: false,
             registry: observable.map(),
             get all() {
                return this.registry.values();
              },
             loadAll:action.bound(function () {
                console.log(this);
                this.request()
             }),
             request: () => { 
                console.log(this) //This will give context of all the function outside object that is what I want in above example.
                console.log('hello');
               },
           });
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda