Assume we have the following object
const foo = {
bar: "hello "
}
Is it possible to achieve the following result:
console.log(foo.bar) // logs "hello "
console.log(foo.bar("world")) // logs "hello world"
I want to be able to get or call the same property and apply a function if called
I have tried using Proxy https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy with apply() handler, however I was not able to find a working solution, every attempt ends at This expression is not callable. Type 'String' has no call signatures.