Not always. When adding hooks (event handlers) in emacs, it compares functions to ensure that the same hook function isn’t added twice.
This is by convention there, but the same idea can be extended to JS: how often do you really want to trigger the same function multiple times on an event? Without the ability to compare functions this is impossible to implement.
Mathematically, there is no way to test two functions for equality, that means any language has to use a proxy of some kind. Many use some sort of pointer value, but in any language where it’s easy to make functions at run-time, what does that mean? So sure, it works in some languages, it doesn’t mean it makes sense, and in the long run you’re probably much better off using an explicit proxy.
Comparing functions is just plain nonsensical so is a bit of a red herring in this post.
Not always. When adding hooks (event handlers) in emacs, it compares functions to ensure that the same hook function isn’t added twice.
This is by convention there, but the same idea can be extended to JS: how often do you really want to trigger the same function multiple times on an event? Without the ability to compare functions this is impossible to implement.
Someone doing it doesn’t mean it makes sense.
Mathematically, there is no way to test two functions for equality, that means any language has to use a proxy of some kind. Many use some sort of pointer value, but in any language where it’s easy to make functions at run-time, what does that mean? So sure, it works in some languages, it doesn’t mean it makes sense, and in the long run you’re probably much better off using an explicit proxy.