Code smell? Iterator prototype has iterator method that returns "this"
ljharb at gmail.com
Wed Jul 27 05:16:56 UTC 2016
`new weirdFunction()` would `=== iter` because a constructor that returns
an object (`this`), returns that object when `new`ed - which is how
functions have worked since ES3 (or probably ES1).
On Tue, Jul 26, 2016 at 9:31 PM, Michael Theriot <
michael.lee.theriot at gmail.com> wrote:
> There are many things I still don't understand about iterators...
> var iter = .values();
> iter[Symbol.iterator]() === iter;
> var weirdFunction = iter[Symbol.iterator];
> weirdFunction.call(iter) === iter;
> var weirdInstance = new weirdFunction(); // what is this??
> On Mon, Jul 25, 2016 at 10:19 AM, John Lenz <concavelenz at gmail.com> wrote:
>> This seems ripe for misuse: you don't want two "owners" for the same
>> iterator calling "next" and normally, without the Iterator interface
>> implementation, you would expect "iterator()" to always return an instance
>> of the iterator that the caller "owned".
>> Can anyone provide any historical context on why this method was added to
>> the "iterator"?
>> es-discuss mailing list
>> es-discuss at mozilla.org
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss