Subj : Re: Rhino - How to return a function property from current stope, To : netscape.public.mozilla.jseng From : Igor Bukanov Date : Sat Aug 28 2004 03:34 am Ryan Breen wrote: > On Fri, 27 Aug 2004 20:38:12 +0200, Igor Bukanov wrote: > >>Well, if you in a business of implementing a browser that has to follow >>MSIE, then the advise is not to inherit from ScriptableObjects or use >>defineClass. Instead copy the source of >>org/mozilla/javascript/NativeJavaObject.java and dependable classes like >>JavaMemebers to some other package and start tailoring it to suite your >>browser needs. Trust me, at the end you save a lot of time and you will >>be able to implemnt stuff like document.all('x') to mean the same as >>document.all['x'] or document.all.x... > > > Igor, > > Thanks for the advice -- I think that makes a lot of sense, so I will look > into it. As a data point, I have a bit of a hybrid model between the > NativeObject road you suggest and the purely ScriptableObject approach. > For example, I have already implemented the MSIE array syntactic niceties > by subclassing NativeArray and newObject'ing that as the return value > of document.all and other array methods. > > Is implementing Scriptable and going the NativeObject route the only way > around my current problem? No, this is not the only way, for document.write when document represent ScriptableObject subclass you can implement it as (assuming that window object was the scope you used for defineClass) static jsFunction_write(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) { Scriptable scope = ctorObj.getParentScope(); // scope is window YourDocumentObject document = (YourDocumentObject)ScriptableObject. getProperty(scope, "document"); document.writeImplementation(Context.toString(args[0])); } so function always gets its this through document property. But you may end up with too many such quirks to be manageble. Regards, Igor .