Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Allow passing prototype to toObject, drop selector functions #6

Closed
bergus opened this issue Oct 9, 2019 · 1 comment
Closed

Allow passing prototype to toObject, drop selector functions #6

bergus opened this issue Oct 9, 2019 · 1 comment

Comments

@bergus
Copy link

bergus commented Oct 9, 2019

@ljharb just linked to tc39/proposal-object-from-entries#13, which suggested having a prototype parameter for Object.fromEntries similar to the first parameter of Object.create. Given the issues with objects-as-dictionaries inheriting from Object.prototype, we could nicely deal with them by supporting that in toObject:

const o = Iterator.from().map().map( => [key, value]).toObject(null);
console.assert(Object.getPrototypeOf(o) === null);

This of course would mean dropping the "key selector" and "value selector" parameters, but I don't think those were a good fit anyway. Most mapping over dictionaries will be over their entries using the established key-value tuple convention, and even when reducing an iterator of something else to an object, you could just add an additional map step that produces the tuples. This might even be faster since only one function needs to be called per entry - assuming no inlining occurs and that escape analysis gets the array literal allocated on the stack.

@decompil3d
Copy link
Member

Dropped toObject from the proposal, as Object.fromEntries will do the job for now. We can circle back to toObject later in another proposal once the Iterator Helpers proposal is finalized.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants