Subj : Re: [Rhino] Exposing a ScriptableObject to JavaScripts To : giggler From : nboyd@atg.com (Norris Boyd) Date : Tue Apr 15 2003 02:30 pm The toObject call just wraps method names as declared rather than interpreting prefixes like "jsFunction_". So you should be able to call "task.doSomething()" if you rename "jsFunction_doSomething" to "doSomething". --N giggler wrote: >js file >======= >1. defineClass("MyTask"); >2. var task = new MyTask(); >3. task.doSomething(); >4. out.println('Hello, World!'); > >MyTask class >============ >public class MyTask extends ScriptableObject { > ... > public void jsFunction_doSomething() throws JavaScriptException { > //doSomething > } >} > >My launcher class >================= >1. Context jsContext = Context.enter(); >2. Scriptable scope = new Global(jsContext); >3. Scriptable scope1 = Context.toObject( > System.out, scope); >4. scope.put("out", scope, scope1); >5. jsContext.evaluateReader( > scope, scriptFile, _scriptFilename, 1, null); > > >This works fine for me, however MyTask is an object I want my script >creators to have access to without defining the class first. How can I >expose this object so it is always available to them? > > >I have tried the following without success. I get the "TypeError: >undefined is not a function." error. > >4a. Scriptable scope2 = Context.toObject( > new MyTask(), scope); >4b. scope.put("task", scope, scope2); > >I fail to see what makes MyTask any different than System.out besides >the fact that MyTask is instanced and System.out is a static variable? > > > > .