Code smell? Iterator prototype has iterator method that returns "this"

Claude Pache claude.pache at gmail.com
Wed Jul 27 06:56:38 UTC 2016


> Le 27 juil. 2016 à 07:16, Jordan Harband <ljharb at gmail.com> a écrit :
> 
> `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).

If `weirdFunction` were defined as if by evaluating `function () { return this }`, yes. But in general, functions are not necessarily constructors (just try `new Math.sin` in your favourite JS environment).

—Claude



More information about the es-discuss mailing list