Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8622767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:07:57+00:00 2026-06-12T07:07:57+00:00

I have a javascript class object that I want to use multiple times on

  • 0

I have a javascript class object that I want to use multiple times on the same page, and it requires a setTimeout function to work as it keeps ticking over in the background. However, as you can see in this fiddle, on the timeout call, its only referencing the newest instance of the object. Does anyone know how I can sort it? Preferably, I would like to see how it is done not in jQuery, I like to understand exactly how it does it.

http://jsfiddle.net/cgoddard/yQDLe/20/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:07:58+00:00Added an answer on June 12, 2026 at 7:07 am

    When you write this.doDelayed inside a doubly nested function, the this keyword doesn’t refer to your test object. Instead, it refers to whatever object the currently executing function was called for, which is probably window.

    To overcome this, you have to save your this in the very beginning of the test function, say like this: var $this = this;
    Then you can refer to that very object using $this.

    Besides this, when you write simply x = something, the symbol x is treated like a property on the window object (also known as “global variable”). Therefore, both your doDelayed and construct functions end up on the window object. Consequently, when you do this second time, they both get overwritten. This is why you get same results twice.
    Instead, you should write $this.doDelayed = function() ... (where $this is your saved value of this from above), and do similarly for construct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's suppose I want to create a javascript class/object/function which have a method that
I want to create a Javascript class/object that allow me to have various method:
I have a function in javascript that changes a span class when I click
I have a class (or function-containing object; I've heard that there is no such
I'm trying a more object oriented approach with javascript and have implemented a class
I have some javascript that goes out and fetches a javascript class on another
I have the following class in javascript: function User(aJid){ this.jid = aJid; this.name =
I have in my javascript these 2 functions classes: // product class function Product()
I have a class that stores paths to CSS and Javascript files in arrays.
I am creating a web app that requires the use of a Java Object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.