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

Editorial: Minimize use of the term "callable" #2889

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jmdyck
Copy link
Collaborator

@jmdyck jmdyck commented Sep 4, 2022

In the ECMAScript spec, the term "callable" (as a noun) is synonymous with "function", but that might not be obvious to the reader. (There are languages in which callables are a superset of functions.)

This PR mostly eliminates the word "callable". (I left a few occurrences, e.g. "a function is a callable object" is an informal way to relate concepts.)

The first commit just renames IsCallable to IsFunction. The second commit handles other occurrences. They can probably be squashed for merging.

@ljharb
Copy link
Member

ljharb commented Sep 4, 2022

I think this is a lot of churn for not a lot of benefit - and this change would be problematic if we ever are able to fix the mess that is [[Call]] vs [[Construct]] in the spec - iow, imo things that you can't invoke without new should be typeof function but shouldn't be considered "callable".

@jmdyck
Copy link
Collaborator Author

jmdyck commented Sep 4, 2022

this change would be problematic if we ever are able to fix the mess that is [[Call]] vs [[Construct]] in the spec - iow, imo things that you can't invoke without new should be typeof function but shouldn't be considered "callable".

Yeah, if that ever happens then this PR would probably be mostly churn.

Is it likely to happen? I don't see a proposal for it.

@ljharb
Copy link
Member

ljharb commented Sep 4, 2022

It’s not necessarily normative, and no, there’s nothing pending.

I’m also saying i think it’s churn as-is - proxies aren’t functions but can be callable, as is document.all.

@jmdyck
Copy link
Collaborator Author

jmdyck commented Sep 4, 2022

proxies aren’t functions but can be callable, as is document.all.

So you're saying there are currently things that are callable but that aren't functions. That's interesting. What is your definition of 'callable'? (or maybe, what's your definition of 'function'?)

It looks to me like callable proxies and document.all are objects that support the [[Call]] internal method, and so are functions, according to the spec definition.

@ljharb
Copy link
Member

ljharb commented Sep 4, 2022

If i can’t Function.prototype.toString.call it, it’s not a function, regardless of what typeof says.

@bakkot
Copy link
Contributor

bakkot commented Sep 4, 2022

You can Function.prototype.toString.call both a Proxy for a function and document.all (and a Proxy for document.all, for that matter).

@ljharb
Copy link
Member

ljharb commented Sep 4, 2022

ha, fair enough then.

i still don’t think this PR’s churn is worth it, personally.

@michaelficarra michaelficarra added the editor call to be discussed in the next editor call label Sep 6, 2022
@michaelficarra
Copy link
Member

Discussed at the editor call today. We're going to explore the viability of removing always-throwing [[Call]] and [[Construct]] implementations before deciding which route to take editorially. If it's possible to do that without normative consequences, that would be preferred.

@michaelficarra michaelficarra removed the editor call to be discussed in the next editor call label Sep 8, 2022
@ljharb ljharb marked this pull request as draft September 8, 2022 02:48
@bathos
Copy link
Contributor

bathos commented Sep 27, 2022

@michaelficarra is there somewhere one could learn more about that / see the discussion?

@bathos
Copy link
Contributor

bathos commented Sep 27, 2022

Re: churn, outside ES repos it looks like IsCallable is used by at least the following specs & proposals:

HTML
Web Audio
Web IDL
WebAssembly JSI
WebAssembly JSI Exception Handling
WebDriver
WebDriver BiDi

also CSS Layout API Level 1, but it looks like it’s not used in the real(?) spec (“lasted editor’s draft” in w3c parlance), just its commit history (“latest published version”).

It’s also a term that’s made its way into userland JS a good amount, I think, but I suppose that wouldn’t have much bearing. A bit sad to see it go myself but admittedly can offer no explanation as to why :)

Horrible thing 👻

You can Function.prototype.toString.call both a Proxy for a function and document.all (and a Proxy for document.all, for that matter).

It even “supports instanceof” with a simple shim.

document.all(0).id = "prototype";
Object.create(document.all(0)) instanceof document.all; // true

@ljharb
Copy link
Member

ljharb commented Oct 20, 2022

@bathos although https://npmjs.com/is-callable is usually a transitive dependency, the term definitely has some adoption.

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

Successfully merging this pull request may close these issues.

5 participants