Now I'm studying about this
keyword in Javascript reading Dmitry's article.
http://dmitrysoshnikov.com/ecmascript/chapter-3-this/#function-call-and-non-reference-type
In here, he shows a example.
var foo = {
bar: function () {
console.log(this);
}
};
foo.bar(); // Reference, OK => foo
(foo.bar)(); // Reference, OK => foo
(foo.bar = foo.bar)(); // global?
(false || foo.bar)(); // global?
(foo.bar, foo.bar)(); // global?
I understand about Reference
, and also can understand foo.bar().
Here are my questions.
foo.bar() and (foo.bar)()
Are these two different? I think, parenthesis which wrapping a expression could be omitted by interpreter. I can't catch the focus about this line. I mean, why he added// global?
comment beside this line?(foo.bar = foo.bar)()
In this line, I think the expression inside of parenthesis runs first, so put foo.bar to foo.bar recursively, and call the function foo.bar. right? Then,this
going to befoo
of course. I don't know why he use this code for example. I mean, why he added// global?
comment beside this line?(false || foo.bar)()
In here, first runs logical operator, thanks for parenthesis, and then this equals to (foo.bar)(). right? Then,this
going to befoo
of course. why he added// global?
comment beside this line?(foo.bar, foo.bar)()
In this line, I can't understand the code. What is the result of(function, function)
? and what does this meaning?
I can try this code on jsfiddle and check the result.
But I can't understand why he wrote these to show example for "Function call and non-Reference type". This is subtitle of this article.