[Helma-user] __defineGetter__
jfwittmann
neokolor at gmx.de
Sun Apr 1 23:22:04 CEST 2007
Michael Platzer schrieb:
> Hi list,
>
> One of the cool new features of Helma 1.6.0 will be the ability to
> define methods for retrieving and setting properties throught the use of
> defineGetter, and defineSetter.
> ->
> http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Creating_New_Objects:Defining_Getters_and_Setters
>
In the Mustang includes Rhino JavaScript engine it's already possible.
this was a little test by me with the known prototype lib on server side.
....
function MapAdapter(map) {
this.__has__ = function(name) {
return map.containsKey(name);
}
this.__get__ = function(name) {
return map.get(name);
}
this.__put__ = function(name, value) {
map.put(name, value);
}
this.__delete__ = function(name) {
map.remove(name);
}
this.__getIds__ = function() {
var result = [];
for (var keyIterator = map.keySet().iterator();
keyIterator.hasNext();) {
var key = keyIterator.next();
result.push(key);
}
return result;
}
};
var Hash = function(obj) {
if (obj instanceof java.util.HashMap) {
Object.extend(this, new JSAdapter(new MapAdapter(obj)))
} else {
Object.extend(this, new JSAdapter(new MapAdapter(new
java.util.HashMap())))
Object.extend(this, obj || {});
}
};
....
And here is another blog thread to this interesting topic too.
http://blogs.sun.com/sundararajan/entry/self_javascript_and_jsadapter
Felix
More information about the Helma-user
mailing list