I\'m playing around with different ways to call a function that is an attribute of an Object in Javascript and looking at which type of calls set \'this\' to be the Object a
The difference between the first three cases and the last two cases is that you're storing the bar function in a variable. Functions don't "know" that they're properties of an object. So in the last two cases, you're just calling regular functions.
In last two cases, you could make "this" refer to "foo" by using Function.call or function.apply
f.call(foo)
Call and apply allow you to control what "this" refers to inside the function you're calling.
While functions don't know whether they're attached to an object or not, they do know what scope they're declared in. There's lots of useful stuff you can do based on that. In the last example, you're creating a new scope by doing (f = foo.bar)(), but it has no effect whatsoever.