Why does Array.from also take a mapFn?

Domenic Denicola domenic at domenicdenicola.com
Mon Jun 24 10:22:52 PDT 2013

From: Rick Waldron [waldron.rick at gmail.com]

> One reason is the extra allocation...

> It's not at all arbitrary: filter isn't an operation used to change the value of the items in the returned iterable.

OK, I think I see. This is because `NodeList.prototype.map` behaves differently from `NodeList.prototype.filter`: the former returns an `Array`, but the latter returns a `NodeList`. Thus we need a method of doing "`NodeList.prototype.mapAsOwnType`", which we've decided to make static and call `NodeList.from`.

Makes sense, I guess? I'll try re-reading threads and meeting notes so I can understand why `NodeList.prototype.map` returns an `Array`.

More information about the es-discuss mailing list