Jquery ui widget extension - how to access parent event

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); } } 
+6
source share
1 answer

In jQuery UI> = 1.9, you can use the _super method _super :

 _slide: function() { this._super(); // equivalent to $.Widget.prototype._slide.call( this ); } 

or superApply :

 _slide: function() { this._superApply(arguments); // equivalent to $.Widget.prototype._slide.apply( this, arguments ); } 
+9
source

Source: https://habr.com/ru/post/894611/


All Articles