I have a class, say com.foo.bar.Baz. I can create one of these, no
problems:
js%> var s = Packages.com.foo.bar.Baz()
I don't want to scatter all these full package references
(Packages.com.foo.bar) through code - I want to do:
js%> var s = Baz()
Help!?
On the docs (http://www.mozilla.org/rhino/ScriptingJava.html) is says
"if your scripts access a lot of different Java classes it can get
awkward to use the full package name of the class every time. Rhino
provides a top-level function importPackage that serves the same
purpose as Java's import declaration."
js%> importPackage(com.foo.bar)
But I get an error:
Exception thrown interpreting script:org.mozilla.javascript.EcmaError:
ReferenceError: "importPackage" is not defined. (<cmd>#2)
Is there a way to do this?
Any help is greatly appreciated.
you can also write:
b = Packages.com.foo.bar;
var s = b.Baz();
To use importPackage your root scope must be created with new
ImporterTopLevel(cx).
whate...@gmail.com a écrit :
Thanks a ton - the second idiom you outline (myPackage =
Packages.com.foo.bar) is *exactly* what I want to do.
Cheers,
parki...
On Oct 26, 11:49 am, Christophe Grand <christo...@cgrand.net> wrote:
> To import a single class:
> Baz = Packages.com.foo.bar.Baz;
> var s = Baz();
>
> you can also write:
> b = Packages.com.foo.bar;
> var s = b.Baz();
>
> To use importPackage your root scope must be created with new
> ImporterTopLevel(cx).
>
> whatever...@gmail.com a écrit :