Von Jan Hansen, (Kommentare: 0)

Functions with optional parameters

Today we are having fun refactoring legacy code. In our application there are  functions with various optional parameters.

callRequest(method, params, data, headers, url)

Only method is mandatory, all other parameters are optional. The status quo consists of each parameter being checked for existance, not very pretty...

callRequest(method, params, data, headers, url) {
    if (headers && headers.length > 0) { 
        ... 
    }
    ...
}