¡@

Home 

2014/10/16 ¤W¤È 12:05:23

jquery Programming Glossary: minislider

JavaScript/jQuery variable scope in class (this)

http://stackoverflow.com/questions/17477663/javascript-jquery-variable-scope-in-class-this

writing simple slider for my website. This slider contains list items. I want to use OOP approach. My actual code var miniSlider function objId this.obj # objId this.obj.settings this.obj.settings 'items' 'ul li' this.obj .length this.pagerNext this.obj.find.. click function alert this.obj.settings 'items' I can invoke a few other sliders yes that's why I introduced a class miniSlider mini slider The problem is that when I'm in jQuery this.pagerNext.on click function this is no longer my object but it's.. you the solution to the this problem in your callback but there is another problem in your code. You are calling the miniSlider function without a new operator miniSlider mini slider That means that inside the function this is not a unique object but..

JavaScript/jQuery variable scope in class (this)

http://stackoverflow.com/questions/17477663/javascript-jquery-variable-scope-in-class-this

done way and with multi sliders support EDIT Here is a full code created with a cooperation with SOF community var MiniSlider function objId this.obj # objId this.obj.settings items ul li this.obj .length autoChangeTime 8000 this.obj.activeElement.. 0 self.obj.parent .hasClass stop self.pagerNext.click this.obj.settings.autoChangeTime and invoke new MiniSlider mini slider javascript jquery class oop share improve this question Alex gave you the solution to the this problem.. the name of this function to follow the JavaScript convention that constructors begin with a capital letter. Call it MiniSlider and use it like so new MiniSlider mini slider If you follow this convention which most experienced JavaScript programmers..