Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda