I’m confused what the object[foo] term is referring to. Any hints? I know that bar['unique_prop'] and bar.unique_prop refers to 2
var foo = {unique_prop: 1};
var bar = {unique_prop: 2};
var object = {};
object[foo] = 'value';
alert(object[bar]);
This:
is equivalent to:
However this:
Doesn’t have much sense (object property names cannot be object literals). JS engine will use
foo.toString()(returning e.g."[object Object]"), so in fact you are doing this:which is clearly a bug or a misunderstanding. This behaviour is explained in Member Operators on MDN:
You can however use:
which is equivalent to: