Loading ...
Sorry, an error occurred while loading the content.

12176Re: [JavaScript] Calling setTimeout from a prototyped function

Expand Messages
  • khing2
    Nov 1, 2005
      here is what i came up with based on info i got from the links

      <html>
      <head>

      <script type="text/javascript">
      function myobject(){
      this.myobjectproperty = 0
      this.prefix = null
      }

      myobject.prototype.step = function step(){
      this.myobjectproperty++
      //innerHTML used only in the interest of time. w3C dom solution
      preferred
      //document.body.insertAdjacentHTML
      ("beforeEnd","<br>"+this.prefix+" "+this.myobjectproperty)
      document.body.innerHTML+="<br>"+this.prefix+" "+this.myobjectproperty
      //adding your suggestion

      if(!this.fcall){
      var _this = this
      this.fcall = function() { _this.step()}
      this.objtimer = window.setInterval (this.fcall, 1000);
      }
      if(this.myobjectproperty == 10){window.clearInterval(this.objtimer)}
      }

      </script>

      <body>
      <script>
      objinstance1 = new myobject()
      objinstance2 = new myobject()
      objinstance3 = new myobject()

      objinstance1.prefix = "ob1"
      objinstance2.prefix = "ob2"
      objinstance3.prefix = "ob3"
      //here is where i forsee a problem.
      objinstance1.step()
      objinstance2.step()
      objinstance3.step()
      </script>
      </body>
      </html>

      --- In JavaScript_Official@yahoogroups.com, Garvin Casimir
      <khing2@y...> wrote:
      >
      > I found 2 links discussing this very topic and related
      > topics. Here they are for those interested.
      >
      > http://www.codingforums.com/archive/index.php/index.php?t-
      10531.html
      >
      >
      http://groups.google.com/group/comp.lang.javascript/browse_thread/thr
      ead/501a015eca1f6834/3540602f351a7f8%233540602f351a7f8?
      sa=X&oi=groupsr&start=0&num=3
      >
      > --- khing2 <khing2@y...> wrote:
      >
      > > I am wondering if someone has a workaround for this.
      > > here is the idea.
      > >
      > > function myobject(){
      > > this.myobjectproperty = myobjectproperty
      > > }
      > >
      > > myobject.prototype.incrument = function(){
      > > this.myobjectproperty++
      > > window.setTimeout("uncrument()",1000)
      > > }
      > >
      > > what i have been trying to do is run a setTimeout
      > > from a prototyped
      > > function.. i am not sure what to do...
      > >
      > > I am also wondering how to do a setTimeout for a
      > > function that has an
      > > object as an argument. Any ideas??
      > >
      > >
      > >
      > >
      >
      >
      > HTTP://SILASCO.SYTES.NET/
      >
      >
      >
      > __________________________________
      > Start your day with Yahoo! - Make it your home page!
      > http://www.yahoo.com/r/hs
      >
    • Show all 3 messages in this topic