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

215
Views
How do I get a js library without import

I want to make a js library, and I have all the code. Libraries like Jquery can let you do like

<script src = "..."></script>
<script>
//uses the library
</script>

without the import * from JQuery. How can I do this without declaring the library a modular or importing?

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

0

Assign the top-level object to a property on window, just like jQuery does:

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
// testing jQuery:
console.log(window.$);
console.log(window.jQuery);
console.log($); // same as window.$
console.log(window.jQuery === $);
</script>

<script>
// your module (imagine this was hosted and loaded via the "src" attribute like jQuery)

const myMath = {};

myMath.add = (...numbers) => numbers.reduce((sum, n) => sum + n, 0);

window.MY_MATH = myMath;
</script>
<script>
// use myMath

const {add} = window.MY_MATH;

console.log(add(1, 2, 3, 4)); // 10
</script>

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!