Briz
Briz

Reputation: 536

Can I tell Javascript to call a method from another JS file?

In AppMenu.js,

AppMenu = function()
{
   var scope = this;
}

Also noted:

Star.Bus.addEvent("AppMenu_StatSheet");
Star.Bus.on("AppMenu_StatSheet", scope.AppMenu_StatSheet, scope);
scope.registerApp("Exit Game", "AppMenu/images/exit_button.png", "AppMenu_exit", "");

Further down is a method

scope.AppMenu_StatSheet = function()
{
    showStats();
}

I moved the location of the showStats() method to another js file, and I want the method to send its call there instead of where it originally was going. In Javascript, can I tell the program where to look to call showStats()?

EDIT Curiously, there is no AppMenu.html. I now believe that all of the html is dealt with by a main HTML file in the above folder.

Upvotes: 0

Views: 199

Answers (2)

Declan Cook
Declan Cook

Reputation: 6126

As long as you include both files in your HTML page you'll be fine. Maybe load the file with showStats() before the other one.

Upvotes: 1

Jules
Jules

Reputation: 7223

If you include both Javascript files in your PHP/HTML page, the compiler automatically uses your showStats() function, even when it is called from file1.js and the actual function is located in file2.js.

Upvotes: 1

Related Questions