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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:13:46+00:00 2026-06-01T04:13:46+00:00

Regarding the object below I am getting a ‘this’ is undefined error. This only

  • 0

Regarding the object below I am getting a ” ‘this’ is undefined error”. This only occurs in the next() function block…as commented below, if it is placed in the Effects function block there is no error.

This is only test code…my goal is to pass the element in through the constructor. This test code has it passed in from both the constructor and the function because I’m testing it. Once it passes I will take out the function argument from fade().

Also the Object Usage, happens to be in another object, that is why you see “this” there as well.

Object Usage:

var EffectsObject = new Effects( this.element );
EffectsObject.fade( this.element, 'down', 4000);

Object Definition:

var Effects = function( element ) 
{
    this.element2 = element;
};

Effects.prototype.fade = function( element1, direction, max_time ) 
{
    Effects.elapsed = 0;
    this.element2 = foo;      // works here but not if I put it in next();
    function next() 
    {
        Effects.elapsed += 10;
        if ( direction === 'up' )
        {
            element2.style.opacity = Effects.elapsed / max_time; // fails here
        }
        else if ( direction === 'down' )
        {
            this.element2.style.opacity = ( max_time - Effects.elapsed ) / max_time;
        }
        if ( Effects.elapsed <= max_time ) 
        {
            setTimeout( next, 10 );
        }
    }
    next();
    return true;
};
  • 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-01T04:13:47+00:00Added an answer on June 1, 2026 at 4:13 am

    You need to create a variable that is in the lexical scope of the the next function.

    var that = this;

    above next, and use that in next.

    var that = this;
    function next() {
    // use "that" here
    ... 
    }
    

    The problem is when you define a method on a prototype, and then execute that method on the instance of an object, the context of the method (the scope) is set when you call the method. When that happens this points at the instance on which the method was invoked.

    When you defined next, note it’s not part of any prototype. It’s just a function. When you execute it, the context of the execution (i.e. this) is not the instance of the object.

    When you define that, and then use it in the function, that is in the lexical scope of the next function. When you invoke next, a closure is created, locking the value of that into the execution scope of next.

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

Sidebar

Related Questions

Is this is far as you would go regarding Object Oriented PHP or can
I am creating an object which tracks changes (Updates) regarding the creation, updating and
I have a question regarding events in c#. Lets say I have an object
There is a very particular edge case in cross-domain policies regarding the window.top.Location object...
This is related to my previous question , regarding pulling objects from a dmp
I'm kind of new to Javascript. Any help or suggestion regarding below problem is
I have two questions regarding the behavior of running the below code. Why is
I ran into a problem this week regarding implicit conversions in C# on collections.
I suddenly get the below error. My application was working fine until I probably
Regarding the Castle Automatic Transaction Management Facility; I'm having some difficulties getting operations to

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.