In the following example, a JS object is created:
var obj = {
key1 : {on:'value1', off:'value2'},
key2 : {on:'value3', off:'value4'}
}
Is there a clever method to automatically retrieve the default value of the key1
on
property when only obj.key1
is passed without specifying a property?
var key1State = obj.key1; // I want 'value1' to be returned here instead of obj.key1{...}
Is it feasible to somehow determine within the body of the object definition which property (if any) is being requested when calling the object?