0

Is there something in Oracle Jet that allows you to include a JavaScript file inside another JavaScript file?

I have my first.js with a lot of functions that I'd like to use in other js pages without copy and paste.

I found this question in pure javascript and in particular the John Strickler's answer con match because Oracle Jet use Require Js.

https://docs.oracle.com/middleware/jet320/jet/developer/GUID-15EA25E7-4CA3-45DE-835A-7ED903332722.htm#JETDG330.

But I have problem with loading my page after I have included first page in define.

I'd like to have my functions in appController/main js and can use in all other modules but I don't know if it is possible.

Thank you.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

1 Answers1

1

Oracle JET uses requireJS for loading modules (and files) dynamically.

Documentation can be found on: https://requirejs.org/

What you will need to do to is "transform" your first.js file to a module "format" so that RequireJS can load it and "expose" your functions. Check the documentation for more info: https://requirejs.org/docs/api.html#define

If you have done that, you can use your module anywhere you want and thus don't need copy/pasta.

User404
  • 2,152
  • 2
  • 27
  • 35