determines which implementation to call Single dispatch (JavaScript): single value used for dispatch. Multiple dispatch: uses multiple values. Axel Rauschmayer (2ality.com) Multiple dispatch 2013-11-11 2 / 9
GenericFunction(); plus.addMethod([num, str], function (op1, op2) { ... }); plus.addMethod([str, num], function (op1, op2) { ... }); plus(3, 'abc') plus('abc', 3) (In languages with multiple dispatch, the cases are called methods.) Axel Rauschmayer (2ality.com) Multiple dispatch 2013-11-11 5 / 9
important as this (implicit parameter in single dispatch) Functions become object-oriented, aware of type hierarchy. Benefits: Useful whenever a polymorphic algorithm spans several objects: foo(obj1, obj2, obj3) // collaborators, not data In which object should we put the algorithm? Extend existing “classes” in an easy, modular fashion. Axel Rauschmayer (2ality.com) Multiple dispatch 2013-11-11 6 / 9