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

183
Views
Create a package or a function that behaves as a method?

I would like to create an npm package for common functions that I use and are not part of javascript , but I dont know how can I create them to use them as methods, let me explain myself

For example I want to use a function like

let reverseString = (string) => string.split('').reverse().join('');

For sure I could use it like reverseString(''somethinghere')

But I would like to use it like 'somethinghere'.reverseString()

Thank you so much in advance.....

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

0

Oh. Its not at all related to npm package. You are talking about JS prototypes. Basically you want to add custom function in String class. Not a good idea to do but still if you want you can do

String.prototype.reverseString = function (str) {
    return str.split('').reverse().join('');
  }
about 4 years ago · Juan Pablo Isaza Report

0

Create a .js file with your method:

module.exports = {
  reverseString: (string) => string.split('').reverse().join('')
}

Then elsewhere, use it with require()

const somethinghere = require('myfile.js')

somethinghere.reverseString('hello')
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!