Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] Javascript Objects and Scope
- From: ryan at ryancannon.com (Ryan Cannon)
- Subject: [Javascript] Javascript Objects and Scope
- Date: Fri Nov 18 13:51:01 2005
Hi folks,
I'm just starting with Javascript objects, and I'm having variable
scope issue that I can't seem to resolve. The following works:
function customClass() {
this.myFunc=function() {
// do something
}
}
window.onload=function() {
var foo=new customClass();
foo.test=function() {
interval=setInterval(function() {
if (test)
foo.increment();
else clearInterval(interval);
}, 400);
}
foo.test();
}
Trying to move the interval inside the object, however, fails:
function customClass() {
this.myFunc=function() {
// do something
}
this.test=function() {
interval=setInterval(function() {
if (test)
this.increment();
else clearInterval(interval);
},400);
}
}
window.onload=function() {
var foo=new customClass();
foo.test();
}
I have a feeling this is a scope problem, because javascript doesn't
throw an error. Any ideas?
--
Ryan Cannon
Wordslinger, Webwright
http://RyanCannon.com
- Follow-Ups:
- [Javascript] Javascript Objects and Scope
- From: Jeff Greenberg
- [Javascript] Javascript Objects and Scope
- Prev by Date: [Javascript] Re: Call history.go(-1) in an iFrame from another frame
- Next by Date: [Javascript] Javascript Objects and Scope
- Previous by thread: [Javascript] Re: Javascript Digest, Vol 33, Issue 11
- Next by thread: [Javascript] Javascript Objects and Scope
- Index(es):