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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:59:23+00:00 2026-06-01T02:59:23+00:00

I am having issues accessing public variables from an object in a prototyped function…

  • 0

I am having issues accessing public variables from an object in a prototyped function… from what I have read, this should work, but perhaps someone with a more experienced eye can point out what I am doing wrong.

In this, I am trying to write my own animation object, with self deletion that another manager can use. callback is a command written as a string, x&y are starting position, x2,&y2 are ending position, time is time in seconds, and element is the element that moves. doTime is the result of a benchmark function that executes on page load to correctly set the timeOut offset.

I can create a working version with inside functions, but as this object is created several times, I was wanting to prototype the function to improve creation speed.

Test show that none of the this.vars are reading within the prototype function.

function circDelta(progress) {
    if (progress < .5)
        return (1 - Math.sin(Math.acos(progress))) / 2
    else
        return (2 - (1 - Math.sin(Math.acos(2*(1-progress))))) / 2
}

function animation(element,x,y,x2,y2,time,callback){
    this.e = element;
    this.x = x;
    this.y = y;
    this.x2 = x2;
    this.y2 = y2;
    this.t = time * 1000;
    this.c = callback;
    this.cT = 0;
    this.id = setTimeout(this.frame, doTime);
}

animation.prototype.frame = function(){
    this.cT+=doTime;
    if(this.cT>=this.t)
    {
        this.e.style.left = this.x2+'px';
        this.e.style.top = this.y2+'px';
        if(typeof this.c === 'function')
            this.c();
    }
    else
    {
        this.e.style.left = ((this.x2-this.x)*circDelta(this.t/this.cT))+this.x+'px';
        this.e.style.top = ((this.y2-this.y)*circDelta(this.t/this.cT))+this.y+'px';
        this.id = setTimeout(this.frame, doTime);
    }
};

I am using the function like this:

this.curr_anim = new animation(hC.menus[0],0,0,0,30,1.5,hC.anim_finished);

any help would be greatly appreciated…. Thank you in advance.

  • 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-01T02:59:24+00:00Added an answer on June 1, 2026 at 2:59 am

    you will probably having scoping issues in setInterval call,

    because setInterval will be called after specified interval and with the scope of window object so it will not be able to access object data using this,

    so you need to pass reference of object using a local variable, you can achive this by use of closures in setInterval like this

    var me = this;
    this.id = setTimeout(function() {
        me.frame();
    }, doTime);
    

    so your final code will look like this

    function circDelta(progress) {
        if (progress < .5)
            return (1 - Math.sin(Math.acos(progress))) / 2
        else
            return (2 - (1 - Math.sin(Math.acos(2*(1-progress))))) / 2
    }
    
    function animation(element,x,y,x2,y2,time,callback){
        this.e = element;
        this.x = x;
        this.y = y;
        this.x2 = x2;
        this.y2 = y2;
        this.t = time * 1000;
        this.c = callback;
        this.cT = 0;
    
        var me = this;
        this.id = setTimeout(function() {
              me.frame();
        }, doTime);
    }
    
    animation.prototype.frame = function(){
        this.cT+=doTime;
        if(this.cT>=this.t)
        {
            this.e.style.left = this.x2+'px';
            this.e.style.top = this.y2+'px';
            if(typeof this.c === 'function')
                this.c();
        }
        else
        {
            this.e.style.left = ((this.x2-this.x)*circDelta(this.t/this.cT))+this.x+'px';
            this.e.style.top = ((this.y2-this.y)*circDelta(this.t/this.cT))+this.y+'px';
    
            var me = this;
            this.id = setTimeout(function() {
                 me.frame();
            }, doTime);
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having issues referencing $(this) from within a the nested ajax 'success' function... I know
Im having issues getting this to work, maybe its not even possible? I have
Having some issues accessing my param tags from within actionscript. Essentially I have the
I've read in forums about people having issues with certain data types when accessing
Just in the last week I have been having issues with accessing a JBoss
I'm having an issue properly accessing an NSDictionary built from Flickr data (the flickr.photosets.getPhotos
Still having issues with this problem. Please help if you can. So I am
I am having issues getting the -e and -d file test operators to work
I'm trying to designing a class and I'm having issues with accessing some of
I'm having issues accessing a web service provided by a third party. Looking at

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.