I have a function foo which is called on window.scroll. I want to access the object variables inside foo, for example i want to print the value of hello from the parent object.
var Object = {
hello: "hello",
foo: function(e){
alert(this.hello); //Prints undefined! I want to get this.hello
},
scrollListener: function(){
var _this = this;
$(window).scroll(_this.foo);
},
};
Object.foo({});.hellofromthisand you'll see why.thisin your context refers towindowthisrefers to the scroll event