选项 1 - 在一个对象中返回多个结果
var initKeyValues = function () {
var petKeys = $('#pets input:checked').map(function () {
return $(this).val();
}).get().join('+');
var employeeKey = $('#employee input:checked').map(function () { return $(this).val(); }).get().join('+');}
return {"petKeys": petKeys, "employeeKey": employeeKey}
};
var whenSelectDateFromCalendar = function () {
var result = initKeyValues();
petKeys = result.petKeys;
employeeKey = result.employeeKey;
// or even...
petKeys = result["petKeys"];
employeeKey = result["employeeKey"];
};
选项 2:在数组中返回多个结果
var initKeyValues = function () {
var petKeys = $('#pets input:checked').map(function () {
return $(this).val();
}).get().join('+');
var employeeKey = $('#employee input:checked').map(function () { return $(this).val(); }).get().join('+');}
return [petKeys, employeeKey];
};
var whenSelectDateFromCalendar = function () {
var result = initKeyValues();
petKeys = result[0];
employeeKey = result[1];
};