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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:04:08+00:00 2026-05-16T18:04:08+00:00

var focus = true; function z() { this.t = 0; this.p = function (t)

  • 0
var focus = true;

function z() {
    this.t = 0;
    this.p = function (t) {
        if (focus == true) {
            this.t = t;
            alert(this.t);

        }

    }
}
var zp = new z();
setTimeout('zp.p(0)', 100);
window.setInterval('zp.p(1)', 2000);
var ftimer = setTimeout('focus=false', 2000);

document.addEventListener('mousemove', function (e) {
    clearTimeout(ftimer);
    focus = true;
    ftimer = setTimeout('focus=false', 2000);
}, false);

I have this code. but for some reason it only alerts twice even with continuous mouse movements. I have been working at this and investigating in firebug and focus is true when I am moving my mouse. I have been trying to figure out what is going on.. even if I do this:

function z() {
    this.t = 0;
    this.p = function (t) {
        if (focus == true) {
            this.t = t;

        }
        alert(this.t);

    }
}

It still only alerts twice.

I have tried using a looping setTimeout function too but that doesnt work either. It is driving me crazy.

  • 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-05-16T18:04:09+00:00Added an answer on May 16, 2026 at 6:04 pm

    Good that you found your bug.

    I would write your code using a bit more functions-as-first-class-objects and less eval logic:

    var focus = true;
    function z() {
        var that = this; // we won't always have the correct value of "this"
        this.focus = true;
        this.t = 0;
        this.p = function (t) {
            if (that.focus == true) {
                that.t = t;
                alert(t);
            }
        }
        this.fade = ( function(obj){ return function(){ obj.focus = false; } } )(this); // Using self-invokation
    }
    var zp = new z();
    setTimeout(zp.p, 100, 0);
    window.setInterval(zp.p, 2000, 1);
    var ftimer = setTimeout(zp.fade, 2000);
    document.addEventListener('mousemove', function (e) {
        clearTimeout(ftimer);
        zp.focus = true;
        ftimer = setTimeout(zp.fade, 2000);
    }, false);
    

    I used a self-invoking function on line 10: ( function(obj){ return function(){...} })(this);, and set this to a different variable.

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

Sidebar

Related Questions

$(document).ready(function() { $('#username').focus(function() { $(this).val(''); }) $('#username').blur(function() { var l = $(this).val.length; if (l
Look at this: $('form).submit(function (event) { $(':input.required').trigger('blur'); var num = $('.warning', this).length; alert(num);//Focus here!
I have this validate form function: function ValidateForm() { var chks = document.register.elements['sendto[]']; var
var ref1 = new Firebase(http://gamma.firebase.com/myuser/123,456); ref1.set(123,456); var on1 = ref1.on(value, function(snapshot) { console.log(snapshot.val()); });
$(#htxtEmoney, #htxtPoint).keypress(function(e){ var evt = window.event ? window.event : e; //for compatibility var keyCode
<button type=button value=click me onclick=check_me(); /> function check_me() { //event.preventDefault(); var hello = document.myForm.username.value;
var Foo = Foo || {}; Foo.Controller = (function ($) { var $page =
var fruit = [apple,pear,pear,pear,banana]; How do I remove all pear fruit from this array?
var JavascriptHelper = Backbone.Model.extend(JavascriptHelper, {}, // never initialized as an instance { myFn: function()
var a = document.createElement('div'); a.id = myDiv; and var a = document.createElement('div').id = myDiv;

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.