Đây là một phần của nguồn jquery. Về cơ bản, họ đang xem xét các loại tham số và gán chúng cho các tham số khác nếu cần. Ví dụ: nếu mục trong vị trí "bộ chọn" trong danh sách tham số không phải là một chuỗi, chúng cho rằng nó có nghĩa là tham số "dữ liệu", v.v.
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;
}
}
Nguồn
2011-11-18 21:27:21
+1 thường tự hỏi điều này. – jondavidjohn