Skip to content

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

Draft
jmdyck wants to merge 2 commits into
tc39:mainfrom
jmdyck:callable
Draft

Editorial: Minimize use of the term "callable"#2889
jmdyck wants to merge 2 commits into
tc39:mainfrom
jmdyck:callable

Conversation

@jmdyck

@jmdyck jmdyck commented Sep 4, 2022

Copy link
Copy Markdown
Collaborator

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

ljharb commented Sep 4, 2022

Copy link
Copy Markdown
Member

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

jmdyck commented Sep 4, 2022

Copy link
Copy Markdown
Collaborator Author

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

ljharb commented Sep 4, 2022

Copy link
Copy Markdown
Member

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

jmdyck commented Sep 4, 2022

Copy link
Copy Markdown
Collaborator Author

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

ljharb commented Sep 4, 2022

Copy link
Copy Markdown
Member

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

@bakkot

bakkot commented Sep 4, 2022

Copy link
Copy Markdown
Member

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

ljharb commented Sep 4, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown
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

bathos commented Sep 27, 2022

Copy link
Copy Markdown
Contributor

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

@bathos

bathos commented Sep 27, 2022

Copy link
Copy Markdown
Contributor

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

ljharb commented Oct 20, 2022

Copy link
Copy Markdown
Member

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

@github-actions

github-actions Bot commented Oct 1, 2025

Copy link
Copy Markdown

The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/2889 and as multiple pages at https://tc39.es/ecma262/pr/2889/multipage .

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