You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the first case property computed has value false, while in the second case it has value true.
That difference corresponds to the . access versus the [] access. It is true that in the case of an object the result is the same because the r.h.s is a string.
But what if it weren't a string, if it were something that needed to be computed? (Hence the property computed). Or what if the left hand side were an array an not an object? Or some project dependent "whatever"? Because of these other scenarios it is necessary to disambiguate the the two cases.
In your eval code it is easy enough to identify and correctly compute the equivalence of two cases you mentioned.
anObject.aField parses to
{"type":"MemberExpression","computed":false,"object":{"type":"Identifier","name":"anObject"},"property":{"type":"Identifier","name":"aField"}}
which would be anObject[aField]
Though anObject.aField should be the same as anObject["aField"]
{"type":"MemberExpression","computed":true,"object":{"type":"Identifier","name":"anObject"},"property":{"type":"Literal","value":"aField","raw":"'aField'"}}
The text was updated successfully, but these errors were encountered: