How to refer to members of a function object in javascript? -


i'm trying this:

function foo() { alert(this.bar); } foo.bar = "hello world"; foo(); 

that doesn't work because believe this refers global object (window) rather foo. how make work?

this refer object used call method. default, window object.

in case, should parameter in function object directly using named function available in scope.

function foo() { alert(foo.bar); } foo.bar = "hello world"; foo(); 

you shouldn't use this doing this:

foo.call({}) 

this equal empty object.


Comments