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

218
Visualizações
Why can't I access my custom string prototype from an object method?

I have a custom string prototype that does some actions to a string;

String.prototype.norm_to_ascii=function(){return unescape(encodeURIComponent(this))};

In my example, the string that I want to apply the prototype to is a global object property that lives outside of the SampleObject object. In my actual code it would be referenced like this;

var userObject = {
   name: "SomeName",
   id: "SomeID"
}

It works everywhere in my project (other js files) except for within a particular Object method;

var SampleObject = {   //This is in it's own js file called sampleobject.js
   test: 0,
   doStringThings {
      let something = userObject.id.norm_to_ascii()  //RETURNS userObject.id.norm_to_ascii is not a function
   }
}

So in the SampleObject, I need to use the id, for example, but I need to do some basic decoding of the id value that is in the userObject which is what the string prototype does.

I can use this string prototype elsewhere. This is in a chrome extension so I have defined the prototype in the service worker and it can be used in the popup and content pages as well as the service worker so it must have to do with the object method but I can't figure out why? Can anyone offer any suggestions to expose that prototype to the object method without having to redefine it?

EDIT I should have been more clear in my explanation. I updated my example above.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You forget about this

this.otherTestValue.norm_to_ascii()
about 4 years ago · Juan Pablo Isaza Relatório
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