0

I have a question and I don't know if it is possible to do that.

I have multiple files in .js who are in the same system (each function of every files is available inside the other files).

script_A.js
script_B.js
script_C.js
script_D.js

Inside my script_A.js I have a function loadAllFunction() and inside this function I put some function of the script_B.js, script_C.js and script_D.js that I want to load by default when I call loadAllFunction().

So all works well like this but I am asking if it is possible to push the function I want inside loadAllFunction() directly since the files script_B.js, script_C.js and script_D.js ?

Something like for exemple :

script_B.js :

function loadScriptB() {....}
loadAllFunction(loadScriptB());

script_C.js :

function loadScriptC() {....}
loadAllFunction(loadScriptC());

script_D.js :

function loadScriptD() {....}
loadAllFunction(loadScriptD());

And then I call loadAllFunction() from my script_A.js for load all.

It is possible to do something like this ?

Thanks

Florian Richard
  • 80
  • 1
  • 10

1 Answers1

1

1) You can use word "defer" in <script> command to load script file with loadAllFunction() after all other.

2) You should read this thing. Depending of your task you can use Promise or Deferreds.

Roman Bush
  • 156
  • 1
  • 10
  • Thanks for your answer, yes I can understand to use promise with `script_A.js` for `loadAllFunction()`, but my question is more about the possibility to 'call / append' this function with another function since another script (script_B, C or D) like this `loadAllFunction(loadScriptC());` (from script_C.js) – Florian Richard Nov 06 '19 at 13:02
  • Probably you release very strange logic in your application. Can your show more code? – Roman Bush Nov 07 '19 at 14:11
  • Actually I just put every times all the functions I need to load (from all my scripts, A B C D) into the general function `loadAllFunction()` (who is in script_A), and I just asking me if another method was existing for charge `loadAllFunction()` with all my functions from the other scripts (B C D), but it was more an question that I have, and I think it is not possible to do that .. Anyway thank you for your help :) – Florian Richard Nov 07 '19 at 16:07