I'm writing a short class (first time using class in Javascript) for handling a menu icon for my site. this menu icon need to be able to be instancied multiple time on the same page.
I have an issue when using scroll event fired function that seems to not be affected to the right class instance, here is my pseudo code:
var DynMenu = function(Name) {
this.Name = Name;
this.scrollHandler = function() {
alert("Scroll: "+this.Name);
};
DynMenu.prototype.Pause = function() {
alert("Pausing menu: "+this.Name);
$(window).off("scroll", this.scrollHandler);
};
DynMenu.prototype.Start = function() {
alert("Starting menu: "+this.Name);
$(window).scroll(this.scrollHandler);
};
}
this code is invoked and used with the following:
var RevendMenu = new DynMenu("MenuIcon1");
RevendMenu.Start();
RevendMenu.Pause();
When Scrolling the page (after calling RevendMenu.Start() but before calling RevendMenu.Pause()), I get the message "Scroll: undefined"
May you tell me why I don't get the value of this.Name and how I can fix this?
Thanks a lot Regards Florent