It depends on how the function was called.
If called with a keyword new, it thisrefers to the object that is being created (which will be implicitly returned at the end of the function).
, this window.
:
function Foo()
{
this.name = "Foo" ;
}
myFoo = new Foo() ;
alert( 'myFoo ' + myFoo.name + '\n' + 'window: ' + window.name ) ;
Foo() ;
alert( 'myFoo ' + myFoo.name + '\n' + 'window: ' + window.name ) ;
JavaScript "" , , JavaScript , function "" - invokation ( , new , )