Stage 0
Classification: API Change
Human Validated: KW
Title: Reflect.{isCallable,isConstructor}
Authors: Caitlin Potter
Champions: Caitlin Potter
Last Presented: None
Stage Upgrades:
Stage 1: NA
Stage 2: NA
Stage 2.7: NA
Stage 3: NA
Stage 4: NA
Last Commit: 2020-11-06
Topics: others functions
Keywords: legacy framework
GitHub Link: https://github.com/caitp/TC39-Proposals/blob/HEAD/tc39-reflect-isconstructor-iscallable.md
GitHub Note Link: None

Proposal Description:

Function.isCallable() / Function.isConstructor()

Why are these useful?

  • Help support classes/other new function definitions in legacy framework code without significant changes
  • Expose a pretty important part of the runtime to applications, who also may wish to use them
  • Not require depending on slow (and inconsistent across implementations) Function.toString() processing or try/catch statements

The very tiny normative language:

Function.isCallable ( argument )

When the isCallable function is called with argument argument, the following steps are taken:

  1. If IsCallable(argument) is false, return false.
  2. If argument has a IsClassConstructor internal slot with value true, return false.
  3. Return true.

(Should be “Return IsCallable(argument)”, but adjusted to not report Class constructors as callable, as they throw unconditionally without invoking any author code)

Function.isConstructor ( argument )

When the isConstructor function is called with argument argument, the following steps are taken:

  1. Return IsConstructor(argument).