Subj : Re: [Rhino] can you add default getters/setters? To : mcbp223 From : Igor Bukanov Date : Fri May 07 2004 10:13 am Mike C. wrote: > This would better go into the wishlist newsgroup ;) > > In ASP i can write > Session("key") = "val"; > > And it expands to > Session.Value("key", "val"); > where Value is of type propput (or propputref), in IDL slang. > There is also a getter for Value, so you can write > str = Session("key") which expands to Session.Value("key"). > > Would that be doable in Rhino, so I can supply a getter like > Object Session.jsGetDefault_Value(String key) > and > jsSetDefault_Value(String key, Object val) > to be used by the runtime? It is not possible in Rhino without parser modifications to support Session("key") = "val"; since in JS lvalue can only be either variable name or property reference. But if you can accept replacing ("key") with ["key"], then the only thing you have to do is to override in your ScriptableObject subclass has/get/put methods, something among the lines: Hashtable customMap; public boolean has(String name, Scriptable start) { return super.has(name) || customMap.has(name); } public Object get(String name, Scriptable start) { Object x = super.get(); if (x == NOT_FOUND) { x = customMap.get(name); if (x == null) { x = NOT_FOUND; } } return x; } public void put(String name, Scriptable start, Object value) { if (super.has(name, start)) { super.put(name, start, value); } else if (start != this) { start.put(name, start, value); } else { customMap.put(name); } } And if you really needs that, you still can support Session("key") instead of Session["key"] to read the properties, but then you need to implement Function interface in your class as well. Regards, Igor .