I understand that this may be an anti-pattern, but I'm curious how certain JavaScript libraries have the ability to chain JavaScript functions with optional parenthesis... (e.g. chalk)
An example of this would be...
let test = (new SomeClass()).initiate.parse(1).end;
let test = (new SomeClass()).initiate(1).parse.end;
Is there a way of doing this? I thought about maybe trying to do this with getters but the get initiate()
of SomeClass was overridden by the class function initiate()
.