Subj : Creating and using libraries in Rhino To : netscape.public.mozilla.jseng From : visitus 04 Date : Mon Feb 21 2005 12:01 pm --0-38537110-1109016094=:68098 Content-Type: text/plain; charset=us-ascii I want to combine a bunch of utility functions in a single js file and call those functions in several other files. Is there a capability in Rhino to achieve this? Here is what I tried to do. 1) Created util.lib text file that has one simple utility function function utilFunction1(str1){ java.lang.System.out.println(str1+"\n"); } 2) Create .js file that utilizes scope to call the function in util.lib file context = Context.enter(); sharedScope = context.initStandardObjects(); result = context.evaluateString(sharedScope, "util.lib", "", 1, null); fObj = sharedScope.get("utilFunction1", sharedScope); functionArgs = "This is a test"; result = fObj.call(context, sharedScope, sharedScope, functionArgs); 3) When I run this in js shell, I see error: js: "", line 1: uncaught JavaScript exception: ReferenceError: "util" is not defined. (; line 1) If this cannot be done thro' Rhino, is there any other way in which this can be achieved? Thanks --------------------------------- Do you Yahoo!? Yahoo! Search presents - Jib Jab's 'Second Term' --0-38537110-1109016094=:68098 Content-Type: text/html; charset=us-ascii
I want to combine a bunch of utility functions in a single js file and call those functions in several other files.  Is there a capability in Rhino to achieve this?
 
Here is what I tried to do.
1) Created util.lib text file that has one simple utility function
function utilFunction1(str1){
 java.lang.System.out.println(str1+"\n");
}
 
2) Create .js file that utilizes scope to call the function in util.lib file
 
context = Context.enter();
sharedScope = context.initStandardObjects();
result = context.evaluateString(sharedScope, "util.lib", "<cmd>", 1, null);
fObj = sharedScope.get("utilFunction1", sharedScope);
functionArgs = "This is a test";
result = fObj.call(context, sharedScope, sharedScope, functionArgs);
3) When I run this in js shell, I see error:
js: "<cmd>", line 1: uncaught JavaScript exception: ReferenceError: "util" is not defined. (<cmd>; line 1)
If this cannot be done thro' Rhino, is there any other way in which this can be achieved?
 
Thanks
 


Do you Yahoo!?
Yahoo! Search presents - Jib Jab's 'Second Term' --0-38537110-1109016094=:68098-- .