简体   繁体   English

我可以告诉 Javascript 从另一个 JS 文件调用方法吗?

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

In AppMenu.js,在 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.我将showStats()方法的位置移动到另一个 js 文件,并且我希望该方法将其调用发送到那里,而不是原来的位置。 In Javascript, can I tell the program where to look to call showStats() ?在 Javascript 中,我可以告诉程序在哪里调用showStats()吗?

EDIT Curiously, there is no AppMenu.html.编辑奇怪的是,没有 AppMenu.html。 I now believe that all of the html is dealt with by a main HTML file in the above folder.我现在相信所有 html 都由上述文件夹中的主 HTML 文件处理。

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.如果你在 PHP/HTML 页面中同时包含 Javascript 文件,编译器会自动使用你的 showStats() function,即使它是从 file1.js 调用的,而实际的 ZC1C425268E68385D14AB5074C27Z9 位于文件中。

As long as you include both files in your HTML page you'll be fine.只要您在 HTML 页面中包含这两个文件,就可以了。 Maybe load the file with showStats() before the other one.也许在另一个之前用 showStats() 加载文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM