While reviewing a project, I came across code that can be simplified to:
export abstract class Logger {
private static log(level: LogLevels, ...args: Array<any>) {/**/}
public error(...args: Array<any>): LogData {
return Logger.log(LogLevels.ERROR, ...args);
}
}
export class LoggerService extends Logger {
public error(...args: Array<any>): any {
return this._log.bind(this)(super.error(...args));
}
private _log(logData: LogData) {
let logstashLoggerData = this.extendLoggerData(logData);
return this.logStashApi.log(logstashLoggerData)
.toPromise()
.catch(err => console.error(err));
}
}
I have some concerns regarding the line containing
this._log.bind(this)(super.error(...args));
.
This syntax is new to me, so I want to proceed with caution to avoid causing any issues. Is it related to Promises or .bind()
in any way? Through my testing, it seems like the statement could simply be written as this._log(super.error(...args));
(but why make it more complex?), can someone validate this?