How to access class member variables inside an event handler defined in a class prototype - Javascript
<p>I've seen this solution that works when the event is defined in the constructor:</p>

<p><a href="http://stackoverflow.com/questions/3076010/accessing-class-member-variables-inside-an-event-handler-in-javascript">Accessing class member variables inside an event handler in Javascript</a></p>

<p>But when the handler is defined in the prototype it doesn't have scope to see "var _self" from the previous solution. Is there a variation that will work for code similar to below?</p>

<p>The problem is with the "this" in the "slide" handler... referring to the HTML element instead of the member variables in MyView.</p>

<pre><code>function MyView(wrapperDiv)
{
    this.contentW = 1200;
    this.vboxW = 600;
    this.vboxH = 400;
    this.vboxX = 0;
    this.vboxY = 0;
}

MyView.prototype = {

    initHorizontalScrollBar : function ($bar)
    {
        //create the wrappers for the slider
        if($bar.find('.slider-wrap').length==0)
            $bar.append('&lt;\div class="slider-wrap"&gt;&lt;\div class="slider-horizontal"&gt;&lt;\/div&gt;&lt;\/div&gt;');//append the necessary divs so they're only there if needed
        $bar.find('.slider-wrap').width(this.svgWidth);

        //initialize the JQueryUI slider
        $bar.find('.slider-horizontal').slider({
            orientation: 'horizontal',
            min: 0,
            max: 100,
            range:'min',
            value: 0,
            slide: function(event, ui) {

                var difference = this.contentW-this.vboxW;
                if(difference&lt;=0)
                    return;
                this.vboxX =  (ui.value) / 100 * ( this.contentW-this.vboxW);       // 0 &gt;= ui.value &lt;= 100
                this.svg.setAttribute("viewBox", toViewBoxString(this.vboxX, this.vboxY, this.vboxW, this.vboxH));
                $('ui-slider-range').width(ui.value+'%');//set the height of the range element
            }
          });     


        this.sizeHScrollbar();
    }
};
</code></pre>
