I’ve lately browsed js code and the following syntax keeps coming up:
var foo = bar.bi = function() {...}
This is unfamiliar syntax to me. Is it only to define two names for the same function? If so, why not only define it as bar.bi = function()?
Assigns the same value to the variable and the
biproperty of thebarobject at the same time.This way the object’s property gets the value, but you can still reference it as a variable, which is likely a little faster.
Effectively the same as…
Or you can visualize it as…
So the assignment to
bar.bihappens first. The result returned from the assignment expression is the same function, and that result is assigned tofoo.