This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 26973 - make iterable declarations' iterator prototype objects inherit from %IteratorPrototype%
Summary: make iterable declarations' iterator prototype objects inherit from %Iterator...
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-05 00:57 UTC by Cameron McCormack
Modified: 2016-09-08 21:12 UTC (History)
7 users (show)

See Also:


Attachments

Description Cameron McCormack 2014-10-05 00:57:58 UTC
http://heycam.github.io/webidl/#es-iterator-prototype-object

[[
The internal [[Prototype]] property of an iterator prototype object MUST be the Object.prototype object. 
]]

http://lists.w3.org/Archives/Public/public-script-coord/2014OctDec/0058.html points out that iterator objects in ES6 all inhert from %IteratorPrototype%, so we should do the same with iterator prototype objects generated for iterable declarations.
Comment 1 Brendan Eich 2014-10-05 02:43:26 UTC
The plan is to put much-wanted methods on Iterator.prototype, in ES7. The iteration protocol in JS is still structural, but Iterator() provides an adapter from structural to nominal, with map/filter/etc. handy methods via prototypal inheritance.

Dave should correct me on anything amiss here. I hope this helps improve the web platform sooner.

/be
Comment 2 Boris Zbarsky 2014-10-05 03:30:18 UTC
Yeah, having generic map/filter that apply to any iterable and live on Iterator.prototype (and perhaps some prototypes of other iterables like Set and Map) would be really nice!
Comment 3 Brendan Eich 2014-10-05 05:03:33 UTC
(In reply to Boris Zbarsky from comment #2)
> Yeah, having generic map/filter that apply to any iterable and live on
> Iterator.prototype (and perhaps some prototypes of other iterables like Set
> and Map) would be really nice!

Iterator not iterable, so if Map and Set have standard iterators that delegate to Iterator.prototype, then everything works automagically. You name a map or set on the right of for-of's 'of' and @@iterator does the rest.

Having Map.prototype.map do the @@iterator call and delegate to the returned iterator's map is doable but seems unnecessary when using for-of. When calling someMap.filter directly, of course, it's wanted. Some design freedom here to "do both", IMHO.

/be
Comment 4 Cameron McCormack 2014-10-05 05:16:51 UTC
This would mean that you would write things like:

  myMap.keys().filter((x) => x > 10)

yeah?  To make it a little easier to type than:

  [...myMap.keys()].filter((x) => x > 10)
Comment 5 Brendan Eich 2014-10-05 16:21:14 UTC
(In reply to Cameron McCormack from comment #4)
> This would mean that you would write things like:
> 
>   myMap.keys().filter((x) => x > 10)
> 
> yeah?  To make it a little easier to type than:
> 
>   [...myMap.keys()].filter((x) => x > 10)

Yes, and more efficient too.

(BTW the single-parameter arrow function form does not need parens around the formal parameter: x => x > 10 -- just passing this along in case it needs some publicity. ;-)

/be
Comment 6 Domenic Denicola 2016-09-08 21:12:08 UTC
This appears to have been fixed a while ago.