1. Use optional and default parameters
- use ? between name and data type to mark parameter as optional.
- optional parameters must come after required parameter.
- Developer can also choose to supply a default value for parameter
2. Allowing an arbitrary number of parameters
- Must be same type
function Name(...args:string[]){
}
3. Function overloading
- Programmer can define multiple signatures so caller can call this function in multiple way.
- only one implementation for all signatures.
4. Creating named parameter
- If function has large amount of optional parameters. It's convenient for the consumer to create named parameters so caller only pass in what actually need.
function createButton(caption: string, args?: {autoHide?: boolean, isDefault?: boolean, isCancel?: boolean}) {
createButton("OK", {autoHide: true, isCancel: true});