# introspection of bind functions

**URL:** <https://es.discourse.group/t/introspection-of-bind-functions/1323>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [April 24, 2022, 12:25pm UTC](https://es.discourse.group/t/introspection-of-bind-functions/1323 "2022-04-24T12:25:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thysultan](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thysultan/32/1343_2.png) [@thysultan](https://es.discourse.group/u/thysultan)\
**Post date:** [April 24, 2022, 12:25pm UTC](https://es.discourse.group/t/introspection-of-bind-functions/1323/1 "2022-04-24T12:25:41Z")

</div>

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

```javascript
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.

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [April 24, 2022, 1:00pm UTC](https://es.discourse.group/t/introspection-of-bind-functions/1323/2 "2022-04-24T13:00:35Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![thysultan](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thysultan/32/1343_2.png) [@thysultan](https://es.discourse.group/u/thysultan)\
**Post date:** [April 24, 2022, 2:09pm UTC](https://es.discourse.group/t/introspection-of-bind-functions/1323/3 "2022-04-24T14:09:23Z")

</div>

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...

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 24, 2022, 11:13pm UTC](https://es.discourse.group/t/introspection-of-bind-functions/1323/4 "2022-04-24T23:13:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![thysultan](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thysultan/32/1343_2.png) [@thysultan](https://es.discourse.group/u/thysultan)\
**Post date:** [April 26, 2022, 1:54pm UTC](https://es.discourse.group/t/introspection-of-bind-functions/1323/5 "2022-04-26T13:54:30Z")

</div>

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.
