Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda