Array.prototype enumerables

5 views
Skip to first unread message

Kris Zyp

unread,
Sep 9, 2009, 12:48:36 PM9/9/09
to narw...@googlegroups.com
Could you make Array.prototype additions be non-enumerable when possible
(in ES5 environments)?

if (!Array.prototype.toByteString) {
Array.prototype.toByteString = function(charset) {
return new ByteString(this);
};
}

should become:

if (!Array.prototype.toByteString) {
Array.prototype.toByteString = function(charset) {
return new ByteString(this);
};
if(Object.defineProperty){
Object.defineProperty(Array.prototype, "toByteString",
{enumerable:false});
}
}


And same thing for "toByteArray". I have grown very fond of using for
each(var item in array) for nice terse syntax for iterating over arrays,
but that doesn't work well with Array.prototype enumerables.
Kris


Kris Kowal

unread,
Sep 9, 2009, 5:01:56 PM9/9/09
to narw...@googlegroups.com
On Wed, Sep 9, 2009 at 9:48 AM, Kris Zyp<kri...@gmail.com> wrote:
>
> Could you make Array.prototype additions be non-enumerable when possible
> (in ES5 environments)?
>
> if (!Array.prototype.toByteString) {
>    Array.prototype.toByteString = function(charset) {
>        return new ByteString(this);
>    };
> }
>
> should become:
>
> if (!Array.prototype.toByteString) {
>    Array.prototype.toByteString = function(charset) {
>        return new ByteString(this);
>    };
>    if(Object.defineProperty){
>        Object.defineProperty(Array.prototype, "toByteString",
> {enumerable:false});
>    }
> }

This is very reasonable. We even have a defineProperty stub that we patch in.

http://github.com/tlrobinson/narwhal/issues#issue/43

Kris Kowal

Reply all
Reply to author
Forward
0 new messages