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

136
Views
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 answers
Answer question

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 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!