Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
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 answers
Answer question

0

You forget about this

this.otherTestValue.norm_to_ascii()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!