Ozerich
Ozerich

Reputation: 2000

Create jQuery plugin and than use its context

For example, i want to create Slider.

jQuery.fn.Slider = function(){ 
    var reset = function(){};
    var setValue = function(){};
};

than use it

var slider = $('#slider').Slider();

but i need to use it later, for ex. slider.reset(); slider.setValue(50);...

But i can't return object context in fn.Slider, i think that there is another method for solve my problem.

Upvotes: 1

Views: 63

Answers (1)

Fresheyeball
Fresheyeball

Reputation: 30015

You need to attach your methods to the object, not declare them as private scoped variables.

jQuery.fn.Slider = function(){ 
    this.reset = function(){};
    this.setValue = function(){};
};

Upvotes: 2

Related Questions