introspection of bind functions

Similar to instanceof, a way to introspect if two bound functions share the same function, for example:

let a = () => {}
let b = a.bind()
let c = b.bind()
console.assert(b.instanceof(a))
console.assert(c.instanceof(a))

Whether "c.instanceof(a)" (the second assert) should return true is out there.

Hi @thysultan !

Interesting idea. Do you have some particular situations where this would help? TC39 proposals are often considered based on how well they address a problem (amongst other factors too of course).

Here are a few:

  • When using bound functions as a reactive boxed values, in places that the bound function is used, in order to determine the "color" of the function whether it is a reactive function created internally or an external function and take differing branches based on that.
  • determining if an event listener shares the same function "instance".
  • short circuit on equality comparison when functions share the same internal "instance" to avoid memoization invalidation etc...

For the first, storing the bound functions in a weak collection, or adding a Symbol property on them, seems like it'd suffice?

Additionally, you could memoize the input function so that there's only ever one bound copy of it - which would make it easier to map back from the bound function to the original one.

All definitely possible as it stands, the second more so if the consumer and provider are the same, otherwise there's a lot of state hustling to get it to that state.