JavaScript(Rhino)使用库或包含其他脚本 [英] JavaScript (Rhino) use library or include other scripts

查看:43
本文介绍了JavaScript(Rhino)使用库或包含其他脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JDK6中,是否可以加载一个文件中的每个脚本的多个脚本,并让一个脚本引用另一脚本的方法?有点像包含"?

In JDK6, is there a way to load multiple scripts, each in a file, and have the one script reference a method of another script? Sort of like "include"?

推荐答案

我认为您正在使用 load()方法/属性

load("file1.js");
load("file2.js");
load("file3.js");

methodFromFileOne();
var bar = methodFromFileTwo();
var etc = dotDotDot();

这将加载javascript源文件,类似于PHP中的include/require方式.加载文件后,您就可以调用和运行或使用加载的文件中定义的任何对象.

This will load a javascript source file, similar to how include/require will in PHP. Once you load a file, you'll be able to call and function or use any object defined in the loaded file.

这是您使用Rhino shell时的工作方式,这是我所知道的唯一上下文(您的问题提到了Java SDK,这不在我的经验范围之内)

This is how things work when you're using the Rhino shell, which is the only context I know (your question mentioned the Java SDK, which is outside my area of experience)

这篇关于JavaScript(Rhino)使用库或包含其他脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆