Multiple dispatch selects an implementation from several arguments, extending polymorphism beyond object-oriented single dispatch. A dispatch function emits a value derived from those arguments, and methods implement matching cases. section 13.0 section 13.6
Greeting by animal and language
A greetLang multimethod dispatches on an animal type and a language type. Calling it with a dog and French selects French output; dog and English selects English output. The emitted array must keep the same order as the method wiring. section 13.3 section 13.3
Listing 13.15 Initializing a multimethod with a dispatch function
var greetLangArgsSchema = {
"type": "array",
"prefixItems": [animalSchema, languageSchema]
};
function greetLangDispatch(animal, language) {
if(dev()) {
if(!ajv.validate(greetLangArgsSchema, [animal, language])) {
throw ("greetLang called with invalid arguments: " +
ajv.errorsText(ajv.errors));
}
}
return [animal.type, language.type];
};
var greetLang = multi(greetLangDispatch);
Inspect the dispatch function that validates arguments and emits the animal-language dispatch value. section 13.3

