Picking property by attribute

YR Chen maian330 at gmail.com
Sat Aug 9 11:38:55 PDT 2008


There's no separate "namespace" for enumerable properties. They are
properties with a hidden enumerable flag set. With that said, in ES4, only
non-fixed properties in the public namespace will be enumerable by default.
That means that properties defined in classes will not be enumerable unless
prefixed with |prototype|, and only "custom" properties defined in the
public namespace (which is the default namespace) are enumerable. So if you
don't want a property to be enumerable, just define it in another namespace
and also open that namespace (via |use namespace|). Or you can toggle the
enumerable flag off via some new method whose name escapes me.

Also, let's not add syntax for things that can easily be done with
functions. You can create your own iterator functions and use them, e.g.:

// assuming pythonic generators are in ES4 (there's an equivalent, albeit
uglier, non-generator way)
myDictClass.prototype.own = function() {
    for (var x in this.iterator::get()) {
        if (this.hasOwnProperty(x))
            yield x;
    }
}

for (var x in myDict.own()) ...

-Yuh-Ruey Chen

On Fri, Aug 8, 2008 at 1:07 PM, Ingvar von Schoultz <ingvar-v-s at comhem.se>wrote:

> I think this would be useful:
>
> Get an enumerable property:
>
>     var x = myDict [*enumerable] .someName;
>
>     var x = myDict [*enumerable] [someVariable];
>
> Call the non-enumerable .toString():
>
>     var x = myDict [*!enumerable] .toString();
>
> Distinguish between owned and inherited properties:
>
>     var x = myDict [*own] .someName;
>
>     var x = myDict [*!own] .toString();
>
> Loop through a subset:
>
>     for (var x in myDict [*own]) {...}
>
> The syntax is meant to suggest that we pick a subset, such as
> all the enumerable properties, and then pick a property from
> this subset.
>
> Here's an alternate syntax, more logical but less readable
> in my opinion:
>
>     var x = myDict .:enumerable .someName;
>
>     var x = myDict .!enumerable .toString();
>
> --
> Ingvar von Schoultz
>
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20080809/0e6d15d5/attachment-0002.html 


More information about the Es-discuss mailing list