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

239
Views
How do I export a function from a module for a class that is built into javascript?

I'm trying to export a function to use in another module, but it's one that I'm adding to the String javascript class.

How would I export the function to use in another module?

This is what I tried and it didn't work

String.prototype.trimChars = function(chars) {...}
export {String}

How do I make it so that this function is added to the string class as trimChars?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can simply forgo the export, and import in another module. However, patching objects like this is not recommended, as it can introduce problems, if say, a browser adds a new function to String that happens to have the same name.

// in the other module
import "path/to/module.js";
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!