I want to do:
properties.email.value
without triggering an error like: Can't read 'value' of 'undefined'
However, I don't want to do:
properties.email && properties.email.value
and I don't want to use an helper, something like: get(properties, 'email.value')
.
I really want to keep the syntax properties.email.value
I can solve this by doing:
Object.defineProperty(properties, 'email', {
get: () => properties.email && properties.email.value,
enumerable: true,
configurable: true
});
Now the getter
is in charge of doing my safety check. Perfect.
But I also want to be able to do properties.name.value
safely.
But as the properties
object comes from the API (json), I don't know the full list of properties
possible.
So, is there a way to use this "magical" get
syntax for any prop access like: properties[ANYTHING].value
?