Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support invocation with no this #16

Open
bakkot opened this issue Oct 21, 2019 · 6 comments
Open

Support invocation with no this #16

bakkot opened this issue Oct 21, 2019 · 6 comments

Comments

@bakkot
Copy link
Collaborator

bakkot commented Oct 21, 2019

It's nice to be able to treat functions like Set.from as actual functions which can be passed around, so that you can do stuff like let sets = [ [0, 1], [2, 3] ].map(Set.from). As currently spec'd this does not work because of the If IsConstructor(C) is false, throw a TypeError exception. step.

I think it would make sense to match the behavior of Array.from, which has the behavior of using the realm-default constructor for Array when the this value is not constructible. That way you get the subclassing behavior (where class MyMap extends Map {}; MyMap.of() instanceof MyMap /* true */;) while still allowing the functional-style invocation above.

@ljharb
Copy link
Member

ljharb commented Oct 21, 2019

Although Promise.resolve and Promise.reject and friends fail to have this very useful fallback, I think it would be a mistake to repeat that omission on new statics like these.

@zloirock
Copy link
Contributor

It conflicts with #13

Seems the answer is tc39/ecma262#544

@bakkot
Copy link
Collaborator Author

bakkot commented Oct 21, 2019

The language is currently inconsistent. I think Array.from both is a much stronger precedent and has better behavior than Promise.resolve.

@zloirock
Copy link
Contributor

@bakkot by the link above you could find the explanation why Array.from precedent is not stronger. I like the idea of binding, but if guys who made the current built-ins subclassing conception against it...

@bakkot
Copy link
Collaborator Author

bakkot commented Oct 22, 2019

@zloirock The link above does not contain the claim that Array.from would be a weaker precedent than Promise.resolve for Map.from. (If it did, I'd disagree; Array.from is obviously much more relevant.) The closest it has is Allen speculating we may have been overzealous in giving Array.from its fallback.

I'd be curious to hear if @domenic still agrees with the position he expressed in that thread. Either way, though, I stand by the OP and my previous comment.

@bakkot
Copy link
Collaborator Author

bakkot commented Dec 6, 2023

Per discussion here and the next few days, I'm inclined to ignore the receiver entirely - i.e. no explicit affordances for subclassing. This is consistent with the set methods proposal (union, etc).

Vylpes pushed a commit to Vylpes/Droplet that referenced this issue Jan 2, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [core-js](https://github.com/zloirock/core-js) | dependencies | minor | [`3.34.0` -> `3.35.0`](https://renovatebot.com/diffs/npm/core-js/3.34.0/3.35.0) |

---

### Release Notes

<details>
<summary>zloirock/core-js (core-js)</summary>

### [`v3.35.0`](https://github.com/zloirock/core-js/blob/HEAD/CHANGELOG.md#3350---20231229)

[Compare Source](zloirock/core-js@v3.34.0...v3.35.0)

-   [`{ Map, Set, WeakMap, WeakSet }.{ from, of }`](https://github.com/tc39/proposal-setmap-offrom) became non-generic, following [this](tc39/proposal-setmap-offrom#16 (comment)) and some other notes. Now they can be invoked without `this`, but no longer return subclass instances
-   Fixed handling some cases of non-enumerable symbol keys from `Symbol` polyfill
-   Removed unneeded NodeJS domains-related logic from `queueMicrotask` polyfill
-   Fixed subclassing of wrapped `ArrayBuffer`
-   Refactoring, many different minor optimizations
-   Compat data improvements:
    -   [`Array.fromAsync`](https://github.com/tc39/proposal-array-from-async) marked as [supported from V8 ~ Chrome 121](https://bugs.chromium.org/p/v8/issues/detail?id=13321#c13)
    -   It seems that the ancient [`Array.prototype.push` bug](https://bugs.chromium.org/p/v8/issues/detail?id=12681) is fixed in V8 ~ Chrome 122 (Hallelujah!)
    -   [`ArrayBuffer.prototype.transfer` and friends proposal](https://github.com/tc39/proposal-arraybuffer-transfer) features marked as [supported from FF 122](https://bugzilla.mozilla.org/show_bug.cgi?id=1865103#c8) and Bun 1.0.19
    -   [`Object.groupBy` and `Map.groupBy`](https://github.com/tc39/proposal-array-grouping) marked as supported from Bun 1.0.19
    -   Since [`Iterator` helpers proposal](https://github.com/tc39/proposal-iterator-helpers) methods are still not disabled in Deno, the web compatibility issue why it was disabled in Chromium makes no sense for Deno and fixed in the spec, they marked as supported from Deno 1.37
    -   Added Opera Android 80 and updated [Opera Android 79](https://forums.opera.com/topic/68490/opera-for-android-79) compat data mapping
    -   Added Samsung Internet 24 compat data mapping

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/Droplet/pulls/253
Reviewed-by: Vylpes <[email protected]>
Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants