Oto trochę źródła jquery. Zasadniczo analizują typy parametrów i w razie potrzeby przypisują je do innych parametrów. Na przykład, jeśli pozycja w pozycji "selektora" na liście parametrów nie jest łańcuchem znaków, zakłada się, że miała ona być parametrem "data" i tak dalej.
on: function(types, selector, data, fn, /*INTERNAL*/ one) {
var origFn, type;
// Types can be a map of types/handlers
if (typeof types === "object") {
// (types-Object, selector, data)
if (typeof selector !== "string") {
// (types-Object, data)
data = selector;
selector = undefined;
}
for (type in types) {
this.on(type, selector, data, types[ type ], one);
}
return this;
}
if (data == null && fn == null) {
// (types, fn)
fn = selector;
data = selector = undefined;
} else if (fn == null) {
if (typeof selector === "string") {
// (types, selector, fn)
fn = data;
data = undefined;
} else {
// (types, data, fn)
fn = data;
data = selector;
selector = undefined;
}
}
+1 często się nad tym zastanawiałem. – jondavidjohn