Re: 'this' and setInterval
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: 'this' and setInterval

From: Luke Matuszewski <matuszewski.lukasz@gmail.com>
Date: Sat Nov 19 2005 - 17:26:04 CET

This is quite confusing... we all know that every object created via
'new' has a prototype object shared with all created objects with the
same constructor (assuming that prototype was defined before and not
changed during creation of new objects), so when you do:
Con.prototype.next = function() {
  this.count++;
  if (this.count > 10) clearInterval(this.doNext);
}
and call it via obj.next(); then 'this' should point to obj
itself...(when you call Con.prototype.next() then 'this' references to
only prototype object.
It is wise to do at begginging:
Con = function() {
 var thisRef = this;
...
}

Maybe someelse would post another comments ;-)
Received on Mon Nov 21 03:35:12 2005