About the classic topic of this

Source: Internet
Author: User

I've seen this subject many times.

var x = ten; var foo = {    ,    function() {        var x = +;         returnthis. x;     = foo.bar) (); Alert ((Foo.bar, Foo.bar) () );

Before you start, in the console, enter
A = 1;
b = 2;
(A, B);
will be displayed directly 2 this indicates that the comma operator directly returns the result of a subsequent expression

Look again
A = B and (a = b)
Output 2 indicates that the assignment operator returns the assignment result
Here is equivalent to defining a TMP = Foo.bar () and then TMP ()

But A.b () (A.B) () looks like they're different. An A object calls B () and the second one seems to be a function operation.
In fact, because a.b this expression does not do what operation the compiler will remove a layer of parentheses as A.B () to operate

So here the first two results are definitely the same after two is also

You might ask why the value of the following hint is not 20 but 10.
Because the next two is a function expression, you can think of it as an anonymous function.
They are equivalent

(function() {  var x = +;  Console.log (this//  )returnthis. x;}) ();

About the classic topic of this

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.