for own(...) loop (spin-off from Re:, hasOwnProperty(), and inheritance)

Brendan Eich brendan at
Tue Nov 8 14:35:14 PST 2011

On Nov 8, 2011, at 1:19 PM, Axel Rauschmayer wrote:

> I see two domains for the concept of “own” properties:
> 1. Meta-programming.
> 2. Using objects as dictionaries.

Thanks, good to focus on use-cases. Both would like shorthand and freedom from Object.prototype.hasOwnProperty tamper-proofing.

> Isn’t #2 the majority (at least as far as non-library-programmers are concerned)? Will the concept become less relevant once we have David Herman’s dicts?

We don't know how dicts will fare. Making progress with for own does not interact badly with dicts if we spec them to be for-in'able -- for own (k in d) for d a dict should work, just as for objects.

> I also like the Python-style iterator-based approach, e.g. something like the following:
>      for ([key,value] on pairs(obj)) {
>      }


I like that too, and we have keys/values/items in the strawman (items, not pairs -- after Python). These are own-only. But plain old for-in still benefits from own.

If 'for (let k of keys(obj))' is good enough to de-motivate 'for own (let k in obj)', great. The latter is only slightly shorter (two chars, the way I've coded it with space after own, for the parens saving), but more important: it is a simpler upgrade to existing for-in loops that otherwise need rewriting.


> On Nov 8, 2011, at 21:49 , Brendan Eich wrote:
>> Should provide sugar for the recommended pattern? To make it compose with declarations and destructuring in the for head, it should use a contextual keyword immediately after 'for':
>>   for own (i in o) {
>>     body
>>   }
>> This is a small thing but it might pay off in the long run.
> -- 
> Dr. Axel Rauschmayer
> axel at
> home:
> twitter:
> blog:
> _______________________________________________
> es-discuss mailing list
> es-discuss at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list