[jQuery] variable scope
[jQuery] variable scope
Hello everyone,
I'm new to jQuery and need some help with a trivial question. I'm
trying to program a menu bar and I'm having problems with variable
scope. Below is a snippet of my code:
//
******************************************************************************************************
<script type="text/javascript">
$(document).ready(function()
{
var menubar = new MenuBar();
});
</script>
<script type="text/javascript">
function MenuBar()
{
this.currentIndex = 0;
$('.menu_button').click(this.onClick);
};
MenuBar.prototype.onClick = function(evt)
{
this.currentIndex = 1; //<--Unable to access class variable!!
this.Select(this.currentIndex); //<--Unable to access class
funtion!!
};
MenuBar.prototype.Select = function(index)
{
//code goes here
};
</script>
//
******************************************************************************************************
Once the onClick event is received the scope move from the class to
the actual item itself. How do I access class variables amd functions
after receiving an event??
Any help is greatly appreciated.
-Ted