There is an error in the last line of the code stating :
Uncaught TypeError: Cannot read property 'removeClass' of undefined
why it is that there is no error in last-2nd and last-3rd line, but in the last-line? What's going on here?
var scrolling = {
a : 9,
b: 1,
z: [0,1],
$headerComponent : $(".header-wrapper"),
funcInEvent1: function() {
this.$headerComponent.removeClass("duringScroll-header");
},
rough: function(){
var a = this.z;
console.log(a);
}
};
$(window).on("scroll", function(){
console.log(scrolling.$headerComponent); // <----- NO ERROR (object)
scrolling.rough(); //<----- NO ERROR ( [0,1] );
window.setTimeout(scrolling.funcInEvent1, 300); //<------ ERROR
}
The quirk will be fixed if i replace this
with scrolling
in the 8th line.
funcInEvent1: function() {
scrolling.$headerComponent.removeClass("duringScroll-header");
},