ts 默认参数 可选参数 剩余参数
function buildName(firstName: string, **lastName = "Smith"**) {
return firstName + " " + lastName;
}
let result1 = buildName("Bob"); // "Bob Smith"
function buildName(firstName: string, lastName?: string) {
if (lastName)
return firstName + " " + lastName;
else
return firstName;
}
let result1 = buildName("Bob"); // Bob
let result2 = buildName("Bob", "Adams"); // Bob Adams
function buildName(firstName: string, ...restOfName: string[]) {
return firstName + " " + restOfName.join(" ");
}
let employeeName = buildName("Joseph", "Samuel", "Lucas", "MacKinzie"); //Joseph Samuel Lucas MacKinzie