Subj : RE: Constants To : netscape.public.mozilla.jseng From : "DELHOSTE Fabrice" Date : Thu Jan 22 2004 05:18 pm Thanks. I have hosts objects extending ScriptableObject. Then I use ScriptableObject.defineProperty(...) on the parameter "constructor" in finishInit(...) to define all "static" properties of my object. Is it the good way ? -----Original Message----- From: Igor Bukanov [mailto:igor@fastmail.fm] Sent: jeudi 22 janvier 2004 17:01 To: DELHOSTE Fabrice Subject: Re: Constants DELHOSTE Fabrice wrote: > No answer? > (my question is about JS/Rhino and implementing Host objects serving constants) > > -----Original Message----- > From: DELHOSTE Fabrice > Sent: mardi 20 janvier 2004 19:38 > To: 'mozilla-jseng@mozilla.org' > Subject: Constants > > > Hi, > > In Javascript, is is possible to have constants at the "class" level such as: > > Color.RED > Color.BLUE > > If yes, how can it be implemented in a host object (in order to have them at the required level)? If you host objects extends from ScriptableObject, then use ScriptableObject.defineProperty to add properties to it and pass ScriptableObject.PERMANENT | ScriptableObject.READONLY as attributes. If you rely on automatic scripting of generic Java objects (LiveConnect) available in Rhino, then Rhino will expose all public final fields and getters without setters as immutable properties so you can write: Color = java.lang.Color and then use Color.blue. Regards, Igor .