I am trying to create a jQuery widget that extends from ui.slider . I would like to have my own method that runs on the slide event. I tried to override the parent parameter as usual when you use the slider widget, but I ran into this problem with variable fields:
$.widget( "ui.myslider", $.ui.slider, { _create: function() { this.foo = "bar"; // Outputs "bar" this._mySlide(); // Outputs "undefined" when triggered this.options.slide = this._mySlide; $.ui.slider.prototype._create.apply(this, arguments); }, _mySlide: function() { alert(this.foo); } }
How can I run my function in a slide event and have access to my variable?
Edit: Link to ui.slider source: https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.slider.js
Edit: Solution
$.widget( "ui.myslider", $.ui.slider, { _create: function() { $.ui.slider.prototype._create.apply(this, arguments); this.foo = "bar"; }, _slide: function() { $.ui.slider.prototype._slide.apply(this, arguments); alert(this.foo); } }
source share