Given the code presented, both will do the same. But there are some things to keep in mind:
foo not an object name , it is a variable name .
And variables can change. Consider this:
var bar = foo; foo = null;
Using foo will break the code, but when using this , bar.bar() will work as expected.
Using foo , you make the function dependent on the variable name, so whenever the variable changes, the function is interrupted. This is also an important aspect of code refactoring.
Felix kling
source share