wr1472
02-07-2007, 11:07 AM
Hi
I'm new to javascript, and I'm trying to inmplement OO programming using javascript.
I have created an object called MhukWindow with various attributes, on a test page I am calling a function (downPressedScroller) on a button click, which in turn calls another function(downPressed).
within the downPressed function I try an access a object variable (currentV) which is initialised to zero. but this is coming back as undefined.
I can't fugure out why and this is driving me nuts! I need to understand such a fundamental problem if I am to learn javascript.
please help, my code is outlined below :-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function MhukWindow()
{
this.increment = 2;
this.currentV = 0;
this.scrollTimer = null;
this.currentWindow = 'abc';
//......more variables
this.downPressedScroller = function(wndw)
{
currentWindow = wndw;
alert('current window: ' + this.currentWindow); //ok
this.scrollTimer = setInterval(this.downPressed,2000);
}
this.downPressed = function()
{
alert('current V: ' + this.currentV); //comes back as undefined
}
}
var mhuk = new MhukWindow();
alert('created instance');
</script>
</head>
<body>
<input type="button" value="click me" onclick="mhuk.downPressedScroller('wndw');"/>
</body>
</html>
I'm new to javascript, and I'm trying to inmplement OO programming using javascript.
I have created an object called MhukWindow with various attributes, on a test page I am calling a function (downPressedScroller) on a button click, which in turn calls another function(downPressed).
within the downPressed function I try an access a object variable (currentV) which is initialised to zero. but this is coming back as undefined.
I can't fugure out why and this is driving me nuts! I need to understand such a fundamental problem if I am to learn javascript.
please help, my code is outlined below :-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function MhukWindow()
{
this.increment = 2;
this.currentV = 0;
this.scrollTimer = null;
this.currentWindow = 'abc';
//......more variables
this.downPressedScroller = function(wndw)
{
currentWindow = wndw;
alert('current window: ' + this.currentWindow); //ok
this.scrollTimer = setInterval(this.downPressed,2000);
}
this.downPressed = function()
{
alert('current V: ' + this.currentV); //comes back as undefined
}
}
var mhuk = new MhukWindow();
alert('created instance');
</script>
</head>
<body>
<input type="button" value="click me" onclick="mhuk.downPressedScroller('wndw');"/>
</body>
</html>