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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:22:30+00:00 2026-05-26T14:22:30+00:00

Can anyone tell me why my ‘showDiv_boo’ is undefined inside the class´s method? I

  • 0

Can anyone tell me why my ‘showDiv_boo’ is undefined inside the class´s method?
I also can´t access my class´s methods.

Here´s my class ‘Blink’ class with its properties and methods:

function Blink(div) {
    this.div = div
}
Blink.prototype.counter = 0
Blink.prototype.showDiv_boo = true
Blink.prototype.showDiv = function() {
    this.div.style.visibility = 'visible'
}
Blink.prototype.hideDiv = function() {
    this.div.style.visibility = 'hidden'
}
Blink.prototype.startEngine = function() {
    if (this.showDiv_boo) {
        this.showDiv()
    } else if (!this.showDiv_boo) {
        this.hideDiv()
    }
    this.showDiv_boo = !this.showDiv_boo
    this.counter++
}
Blink.prototype.startEffect = function() {
    this.idEffect = setInterval(this.startEngine, 1000 / 45)
}

So, if I create:

_blink = new Blink(myDiv);
_blink.startEffect();

You can test… the variable ‘showDiv_boo’, is undefined inside the method.

Even, if I set the showDiv_boo inside the method to true, it won´t call my class´s methods showDiv or hideDiv.

Anyone?

Thanks 🙂

  • 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-26T14:22:31+00:00Added an answer on May 26, 2026 at 2:22 pm

    You need to:

    1. use var self and call the method via self.startEngine()
    2. use an anonymous function to wrap the call in [1] i.e. function(){ self.startEngine(); }

    This is because when you just pass this.startEngine or self.startEngine you are just passing the function startEngine without specifying what this is, which in both cases is supplied by the global conext of DOMWindow.

    To give an example…

    function startEngine() { 
      ...code omitted... 
    };
    
    Blink.prototype.startEngine = startEngine;
    
    Blink.prototype.start = function() {
      setTimeout(startEngine, 0);       // obviously wrong, what is this?
      setTimeout(Blink.startEngine, 0); // actually the same as line above, although not as obvious
      setTimeout(startEngine.bind(this), 0); // works correctly
    }
    

    works to add code to the prototype and if used in the anonymous function will work as expected, but if you just use Blink.startEngine as the callback it is exactly the same as using startEngine only the second is more obviously wrong because there’s no object it is being called on so you’d expect this to be whatever is supplied by the context.

    The other way you could do this without using the anonymous function would be

      Blink.startEngine.bind(self)
    

    Which returns a function that will call startEngine with the correct this same as explicitly creating the anonymous function and wrapping the call to self.startEngine()

    Heres a link to a fiddle to play around with the differences: http://jsfiddle.net/bonza_labs/MdeTF/

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

Sidebar

Related Questions

Can anyone tell me what's wrong with this code? class Dataset < ActiveRecord::Base has_many
Can anyone tell me why this code would throw an undefined is not a
Can anyone tell me ifwe can access the permissions that each application that a
Can anyone tell me what am i missing here: http://www.latitude18films.com/webtest/international.html All my Thumbnail with
Can anyone tell me why the parenthesis are doubled here? self.__items.append((module, item))
Can anyone tell me if the following CSS is valid? .class { background-color:none; }
Can anyone tell me why this isn't working for me? Example page here http://totalcommunitycollegemove.com/post-438.html
Can anyone tell me how I can access the text after the < br
Can anyone tell me what syntax highlighting theme is in use here? http://jamierumbelow.net/images/code.png Jamie
Can anyone tell me whether Helvetica is a browser base font? If so, it

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.