Subj : Re: Constants To : DELHOSTE Fabrice From : Igor Bukanov Date : Thu Jan 22 2004 05:01 pm 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 .