objects with "get" properties

George Staikos staikos at kde.org
Mon Jun 16 17:35:09 CEST 2003


On Thursday 01 January 1970 05:01, Maciej Stachowiak wrote:

> >  Here's an example:
> >
> > var someObject = {
> >       _someMember : "foo",
> >       get someProperty() {
> >                return this._someMember + this._someMember;
> >       }
> > };
> >
> > someObject.someProperty == "foofoo"
> >
> >    Is this part of the spec, or a Mozilla-ism?
>
> It's a Mozilla-ism and not part of any current spec. It's part of their
> proposal for the next version of ECMAScript, but it's unclear if that
> will ever go through, and if it will continue to include this change
> when it does.

   Actually after playing with it further, I think it might be a bad idea to 
include this in the spec anyways.  It seems to be context sensitive.  I have 
seen code that mozilla happily parses and uses that contains member variables 
named "get" also.  Seems like a horrible thing to have to parser.

> >    It was easy to add the parser support for this, but I'm not exactly
> > sure
> > what the best approach is to implement this.  Properties seem to
> > explicitly
> > have Values as the value (go figure ;)) which doesn't work too well
> > for this
> > case.  Should there be a class FunctionValue : public Value  that gets
> > executed in the object context whenever its value is requested?  Is
> > there a
> > better approach?
>
> If you decide to implement this, I think a better approach would be to
> have a separate table of getter properties, and a similar table of
> setter properties. Then the ObjectImp::get method could check the
> getter properties table separately from the regular property map. These
> tables could be consulted before the property map when getting and
> setting.
>
> Is there a site that needs this feature to work properly?

  I noticed the code in mozilla's xpfe.

-- 
George Staikos
KDE Developer				http://www.kde.org/
Staikos Computing Services Inc.		http://www.staikos.net/



More information about the Khtml-devel mailing list