Reference: multimethod.js

Kris Jordan:

Inspired by Clojure's multimethods, multimethod.js provides a functional alternative to classical, prototype based polymorphism.

multimethod.js builds functions which dispatch on arbitrary predicates in Javascript using a fluent style.

Multimethod iterates through each 'method' registered with when and performs an equality test on the dispatchValue and each method's match value.

I wonder whether a linear search for the dispatch value will scale. I prefer to see some kind of hash-map based solution. Is it possible to serialize the object to JSON and use the resulting String as a key?

Still, I enjoy seeing inter-language cross-pollination. It is also a nice translation from a functional language to a prototype language. The fluent interface does the job extremely well.

Kris Jordan deserves a follow on GitHub.