Basically, I want to build an object such that the following would be possible:
console.log(secretObject) // Outputs: 'A secret'
console.log(secretObject.secretKey) // Outputs: 523
So just like a normal object except when I call the object itself, instead of returning {secretKey: 523}
it would return some other value.
Is this possible?
Edit: I am aware of toString(), but I want to know if there is a solution that would allow for any return value.
For some context, in my function I have many locations where I return false
however I now realise that in only one of these cases I also need to return an additional value. Of course I can figure out a different way to do it, but I thought a relatively elegant solution would be to return an object that itself 'returned' false, but also could potentially contain other information inside.
So it's more out of curiosity than necessity, as to whether it is possible or not.