var obj = {};
var r1 = (obj['toString'])();
var m1 = obj['toString'];
var r2 = m1();
var r3 = (obj.toString)();
var m2 = obj.toString;
var r4 = m2();
r1
and r3
expectedly contain correct result: "[object Object]"
, while r2
and r4
contain "[object Undefined]"
showing that m1
and m2
are not bound to object.
I can't fully comprehend how obj['toString']()
is executed. I always looked this way, (obj['toString'])()
-> (function obj)()
. Turns out that function invocation operator looks back on what is the context. I would expect operator to not know where operands come from.
Can anyone properly explain this behavior?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…