好奇。是否有更简单/更好的方法来编写以下代码?我只需要两个参数选项和回调。可以在没有任何参数的情况下调用该函数,只需要回调,或者使用选项哈希和回调。
function () {
if (typeof arguments[0] === "function") {
callback = arguments[0];
} else if (arguments[0] && typeof arguments[0] === "object" && typeof arguments[1] === "function") {
options = arguments[0];
callback = arguments[1];
}
...
...
}
答案 0 :(得分:2)
function (options, callback) {
if (typeof options === "function") {
callback = options;
options = {};
}
// code
}