Re: __defineGetter__ for existing HopObject properties

Juerg Lehni <[email protected]> Wed, 29 Oct 2008 21:26:59 +0000
Newsgroups gmane.comp.java.helma.general
Message-ID <[email protected]>
Hi,

Almost a year later, here a patch that gets this to work.

http://helma.org/bugs/show_bug.cgi?id=3D647

With this in place, we can do neat things like adding support for  =

watch / unwatch to HopObjects:

HopObject.prototype.watch =3D function(prop, handler) {
	this.__defineGetter__(prop, function() {
		this.unwatch(prop);
		var value =3D this[prop];
		this.watch(prop, handler);
		return value;
	});
	this.__defineSetter__(prop, function(value) {
		this.unwatch(prop);
		var ret =3D handler.call(this, prop, this[prop], value);
		if (ret !=3D=3D undefined)
			value =3D ret;
		this[prop] =3D value;
		this.watch(prop, handler);
	});
}

HopObject.prototype.unwatch =3D function(prop) {
	delete this[prop];
}

I am curious to find out if this can make it into Helma 1.6.3 (or  =

later).

J=FCrg

On 20 Nov 2007, at 18:10, Joshua Paine wrote:

> Walter Krivanek, VividVisions wrote:
>> I can't use __defineGetter__ for properties of a HopObject, which are
>> defined in type.properties, can I?
>
> Looks like no. Which is at odds with the treatment of standard
> properties. E.g., in Rhino and Firefox 2,
>
> a =3D { a:'hi' };
> a.__defineGetter__('a',function(){ return 'bye'; });
> a.a;
>
> the above code returns "bye". But apparently in Firefox 3 you'll  =

> have to
> delete a.a first before you can define a getter for it (which makes
> sense to me). I don't know if that works with HopObjects, and I also
> don't know if it would result in that property actually being deleted.
>
> You can't access the stored value of the original property from the
> getter anyway, so trying to overload the actual property seems like a
> bad idea to me. In one case where I've needed a getter/setter (stored
> the value in the DB as an Int unix timestamp, wanted to work with it  =

> as
> a Date object) I just named the property .modified_ and wrote my  =

> getters
> and setters for .modified.
>
> -Joshua
> _______________________________________________
> Helma-user mailing list
> [email protected]
> http://helma.org/mailman/listinfo/helma-user