The second option sounds fine to me. I might suggest having a look at
the way the various native error constructors are set up [1], i.e.
create an IdFunctionObject instance and a prototype object, set the
appropriate values on the prototype, including "constructor" to the
function instance itself (non-enumerable), and call markAsConstructor
on the function with the prototype.

Now you have your complete constructor, which you can set properties
on, set as the property of another object, or do whatever you like
with. exportAsJSClass is largely a specialisation of the this above
behaviour.

Am I missing anything?

Raphael

[1] 
http://mxr.mozilla.org/js/source/js/rhino/src/org/mozilla/javascript/NativeGlobal.java#132


On Sep 23, 11:30 am, Daniel Friesen <[email protected]>
wrote:
> I've been using IdScriptableObject to implement a few classes.
> Normally I've been using exportAsJSClass to define these classes.
>
> However I'm now in a situation where that isn't working.
> exportAsJSClass defines a top-level scope property, however I'm now in
> the case where rather than wanting it in the top level scope I need to
> define it on a object I have.
> (ie: Rather than defining class Foo as global.Foo I want to define it as
> x.Foo where x is a ScriptableObject I have)
>
> The issue is this:
> - exportAsJSClass does not accept an object to define it on
> -- exportAsJSClass calls ctor.exportAsScopeProperty(); (addAsProperty
> can define it on an object rather than as top-level)
> - prototypeValues.createPrecachedConstructor(); is necessary to get ctor
> -- prototypeValues is private and cannot be used in subclasses to get a ctor
>
> Could we get another method to handle this case. Possible solutions:
> A) An exportAsJSClass that accepts a object and calls addAsProperty(obj)
> instead of exportAsScopeProperty
> B) An alternate method that does everything in exportAsJSClass EXCEPT
> call ctor.exportAsScopeProperty(); and returns ctor
> -- exportAsJSClass can call it to get the ctor and run
> ctor.exportAsScopeProperty();
> -- We can also call it to run addAsProperty
> -- It'll also let us define classes in other properties by running that
> method, then calling ScriptableObject.defineProperty ourselves (which is
> what addAsProperty calls, and exportAsScopeProperty just calls
> addAsProperty) and gives us the ability to define things that are
> enumerable.
>
> I think the latter option is better.
>
> --
> ~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]

_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to