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

138
Vistas
React - using functions from another file

I have two JS files (functions.js and app.js) functions.js - contains a big amount of functions ( so putting them together with app.js - isn't best option ). The regular and arrow functions can be passed with import * as funcs from './functions' or import {func1, func2, func3, ...} from './functions', but when I get to the functions with .prototype ( Array.prototype/ HTMLElement.prototype ) I don't know how to execute them.

Example for a function:

HTMLElement.prototype.findRect = () => {
  console.log("CODE HERE...")
}

Someone has an idea how to pass those functions?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

These are almost like a global function, it needs to be executed once, but after that, you don't have to keep calling it.

Say a file 'abc.js',

  ABC.prototype.go = () => {}

In another file app.js

  import 'abc.js'

  const a = new ABC()
  a.go()

These prototype is the methods that you can dynamically add to the class ABC. Here ABC is a class such as HTMLElement, Array and etc. You can't invoke them directly, instead you can invoke any instance after you create one out of this class.

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