Subj : Rhino: Adding an existing java object to a scope. To : netscape.public.mozilla.jseng From : Keith Tingle Date : Tue Nov 09 2004 02:44 pm Is there a way to set an object's prototype without using Context::newObject() to create the object and assign the prototype all at once? I have objects that are artifacts of a large system of objects that I would like to add late (long after they have been created on the heap) to the scope of the scripts. If I set bRhinoCreates = true in the following java code it results in; >> TypeError: undefined is not a function.<< import org.mozilla.javascript.*; public class Elmo extends ScriptableObject { public String getClassName() { return "Elmo"; } public void jsFunction_tickleMe() { System.out.println("Haha!"); } public static void main(String[] args) { try { Context context = Context.enter(); Scriptable scope = context.initStandardObjects(null); Elmo elmo = null; boolean bRhinoCreates = true; // Add Elmo as a class type ScriptableObject.defineClass(scope, Elmo.class); if (bRhinoCreates) { // Works, object created in Rhino elmo = (Elmo) context.newObject(scope, "Elmo"); } else { // Doesn't work when I create the object myself, // am I missing a step??? elmo = new Elmo(); } // Add object to scope scope.put("elmo", scope, elmo); context.evaluateString(scope, "elmo.tickleMe();", "", 0, null); Context.exit(); } catch (Exception e) { e.printStackTrace(); } } } .