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 8370687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:58:22+00:00 2026-06-09T13:58:22+00:00

This jsFiddle highlights my issue. It is mimicking some functionality I have where an

  • 0

This jsFiddle highlights my issue.
It is mimicking some functionality I have where an Object is defined and sent to the Page via socket.io.

I have a setInterval function checking if Pots is a function, and when it is I fire an Event. During that Event I try to instantiate a new instance of Pots only to be told that it is undefined.

The code:

var Pots;

$(document).ready(function(){
    var timerId = 0;
    var otherTimer = 0;

    otherTimer = setInterval(function() { console.log("Creating"); Pots = function() {}; }, 5000);

    timerId = setInterval(function() {
        console.log("Checking");

        if (_.isFunction(Pots)) {
            console.log(Pots);
            clearInterval(timerId);
            clearInterval(otherTimer);

            var evt = document.createEvent('Event');
            evt.initEvent('ObjectsAvailable', true, true);
            document.dispatchEvent(evt);
        }

    }, 1000);

});

document.addEventListener('ObjectsAvailable', function(e) {
    console.log(Pots);
    var Pots = new Pots();
});  

EDIT
Posted this comment below:
I should point out that Pots is actually a Backbonejs Collection with this declaration: var Pots = Backbone.Collection.extend({model: Pot});. The reason I did the event is because there IS a time when “Pots” isn’t set (probably before the browser has loaded the file with Pots declared). The jsFiddle was just to simulate that time exists. In my actual code “otherTimer” doesn’t exist and Pots IS eventually a Function but when I try to use it during the ObjectsAvailable event, it doesn’t work.

  • 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-09T13:58:24+00:00Added an answer on June 9, 2026 at 1:58 pm

    You never set the global variable “Pots” to any value, so it remains undefined.

    The “ObjectsAvailable” handler looks like it attempts to set it, but

    1. It tries to call “Pots()” to do so, so that won’t work, and
    2. It declares a local variable “Pots” too, so that hides the global one.

    Another note: the fiddle is set up with the code to be run in the window “load” handler, so the “ready” handler is redundant.

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

Sidebar

Related Questions

I have this jsfiddle . When I move the script from the upper panel
Have a look at this jsfiddle: http://jsfiddle.net/Dh96F/1/ The Expand button will animate the widening
I have been trying to get this jsfiddle to work. So far without luck.
Currently I have a stacked bar chart like this ( jsfiddle demo ) I
I have elements structured roughly like this: http://jsfiddle.net/zyySd/ Is there any way to achieve
I have a setup like this: http://jsfiddle.net/zzjSC/3/ and I am wondering why the surrounding
Check this jsfiddle , and have a look at the console. $$ is not
Please see this jsFiddle: https://jsfiddle.net/Wmq6f/ I have a textarea that has a background image,
I have a div like this: http://jsfiddle.net/ANvpS/ . How can I highlight every other
I have this jsfiddle http://jsfiddle.net/fwQq4/19/ Here I have the wrapper class ( div.wrapper )

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.