Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is possible to include js file into another js file?

444 views
Skip to first unread message

Ivana

unread,
May 23, 2010, 12:22:50 PM5/23/10
to
Hi,

I need to define variables and functions in one javascript file, and than
include this file into another javascript file and use them. Is that
possible (even if is needed to use java interface)?

Thank you a lot.
Ivana


Dan Howard

unread,
May 24, 2010, 7:57:27 AM5/24/10
to
Hi Ivana,

What I do is combine Rhino with Velocity. So a get a script and use
Velocity like a pre-processor.

So I have code like this:

// Some script.
var hello = 10;
#include("/common/StringUtil.js")

The #include is a velocity macro which inserts the other js file into
the current one. Usually I would place these at the bottom of the js file.

If you haven't used Velocity there is good documentation here:
http://velocity.apache.org/

Daryl Stultz

unread,
May 24, 2010, 8:18:17 AM5/24/10
to Rhino JS User List
On Sun, May 23, 2010 at 12:22 PM, Ivana <iva.su...@gmail.com> wrote:

> Hi,
>
> I need to define variables and functions in one javascript file, and than
> include this file into another javascript file and use them. Is that
> possible (even if is needed to use java interface)?
>

I use an approach similar to Dan's however I'd like to replace it with
"require". There's been some work done here to support the "require()"
function, I don't know much of the details, maybe someone else here can
cover it.


--
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
http://www.opentempo.com
mailto:daryl....@opentempo.com

Mark Porter

unread,
May 24, 2010, 11:39:45 AM5/24/10
to
You can use Rhino's CommonJS support by implementing
org.mozilla.javascript.commonjs.module.Require, which can be done
inside JS. I am using this in Myna[1] and you can see how I'm doing it
here[2]. Basically you need to let Rhino know how to resolve CommonJS
classpaths, and it takes care of the rest.

Note: Rhino's CommonJS support is only implemented in CVS right now,
so you'll need to build from CVS. if you are feeling lazy you can grab
my js.jar build from [3].

[1]:http://www.mynajs.org
[2]:http://code.google.com/p/myna/source/browse/trunk/1.0/web/shared/
js/libOO/CommonJS.sjs?spec=svn109&r=109
[3]:http://myna.googlecode.com/svn-history/r109/trunk/1.0/jars/js.jar
----------------------------------------------------------
Mark Porter

Myna JavaScript Application Server
Easy server-side JS on a Java platform
http://www.mynajs.org

On May 24, 6:18 am, Daryl Stultz <da...@6degrees.com> wrote:

> mailto:daryl.stu...@opentempo.com

0 new messages