Javascript - cross-file - function - access

Hello.
I organized my javascript functions in separate files.
Let´s say I have a file fileA.js that contains the following function:

var fileA = (function fileA() {

    "use strict";

    function a1() {
        return 'resulttext_a1';
    }

     function a2() {
          return 'resulttext_a2';

    return {
          a1:a1,
          a2:a2
    };
}());



I can call a1 or a2 functions from php inside the script tags e.g. by using fileA.a1.
That works fine.
But let´s imagine I have fileB with functions b1 and b2.
How can I "cross-refer" to e.g. fileA.1 inside of e.g. b1?

I tried inside b1 using this.fileB.b1, but that did not work.
I added both files to the javascript libraries, but that does not work.
Also the using of "this" is difficult because of "use strict"....

Can anybody help please? Thanks a lot.
1 comment

Hello, Adrian.
Why doesn't simple fileA.a1 work for you? a1 and a2 appears in completion list after "fileA.", and go to declaration also works. And in your code example anonymous function can be used, i.e. you declare variable and function named fileA, which is confusing.
Adding files to libraries isn't nessesary either.

Regards,
Konstantin

0

Please sign in to leave a comment.