Syntax Assignment var a = bc = function () {}

I have been looking through js code lately and the following syntax continues to grow:

var foo = bar.bi = function() {...}

This is an unfamiliar syntax for me. Do I need to define only two names for the same function? If so, why not just define it as bar.bi = function()?

+5
source share
5 answers

Assigns the same value to a variable and property of an biobject barat the same time.

Thus, the property of the object gets the value, but you can still refer to it as a variable, which is probably a little faster.

Effectively the same as ...

bar.bi = function() {...};
var foo = bar.bi;

foo === bar.bi; // true

Or you can visualize it as ...

var foo = ( bar.bi = function() {...} );

, bar.bi. , , , foo.

+6

2, , .

bar.bi();

bar, :

foo.call(bar);

, :

foo();

foo. , foo , :

bar.bi.call(window);
+1

var r = x = 3;

3 x, r, .

3, - bar.bi - x.

+1
var foo = bar.bi = function() {...};



bar.bi === function() {...} //true

foo === bar.bi //true

bar , bi.

0

All Articles