我可以告诉 Javascript 从另一个 JS 文件调用方法吗?
在 AppMenu.js 中,
AppMenu = function()
{
var scope = this;
}
还注意到:
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", "");
再往下是一个方法,
scope.AppMenu_StatSheet = function()
{
showStats();
}
我将 showStats()
方法的位置移动到另一个 js 文件,并且我希望该方法将其调用发送到那里,而不是原来的位置正在去。在 Javascript 中,我可以告诉程序在哪里调用 showStats()
吗?
编辑 奇怪的是,没有 AppMenu.html。我现在相信所有 html 都是由上述文件夹中的主 HTML 文件处理的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在 PHP/HTML 页面中包含这两个 Javascript 文件,编译器会自动使用您的 showStats() 函数,即使从 file1.js 调用该函数且实际函数位于 file2.js 中也是如此。
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.
只要将这两个文件包含在 HTML 页面中就可以了。也许在另一个文件之前使用 showStats() 加载该文件。
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.