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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:00:50+00:00 2026-06-09T05:00:50+00:00

one of my classes in Javascript needs to be updated with Json sometimes. I

  • 0

one of my classes in Javascript needs to be “updated” with Json sometimes. I have always done a function, that updates the array of data, given an id, but now i wanted to do it more encapsulated (Function update, inside the class).

What i made:

function File(data){
        this.data = data;

        this.update = function (callback){
            var set = function(ajaxData){
                this.data = ajaxData.PcbFile;
            }
            getPcbFile(data.id, function(ajaxData){
                set(ajaxData);
                callback();
            });
        };
    }

But, this.data = ajaxData.PcbFile; doesen’t work… My object still with the last data set, and not the updated one. The function SET, i created as another attempt to set the data.

There is no problem on the ajax, since i debuged the ajaxData, and it’s ok (when i update).

So, how do i really access the object property data from an inside function?

(sorry for my english…)

  • 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-09T05:00:52+00:00Added an answer on June 9, 2026 at 5:00 am

    I learned this the hard way, you have to be careful with this. It always refers to the this in the current scope, not it’s containing object. Whenever you wrap something in function() { ... }, this becomes of a different scope. In your case, duplicate the object to a local variable and manipulate it’s .data property.

    function File(data){
        this.data = data;
        var file = this; //call the variable whatever you want
        this.update = function (callback){
            var set = function(ajaxData){
                file.data = ajaxData.PcbFile;
            }
            getPcbFile(data.id, function(ajaxData){
                set(ajaxData);
                callback();
            });
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button in one of my classes that i create it with
I have a set of classes that work together (I'm coding in javascript). There
I have a bit of javascript that I have used successfully on one page,
I have a javascript function that manipulates the DOM when it is called (adds
I have a php script that generates php and javascript wrapper classes that handle
This is the code for one of my javascript classes: function Foo(text) { var
I have two classes one of which inherits from the other. Im trying to
All -- I have these two methods in one of my classes: public static
I have a field for addedBy in one of my classes. I've set up
I have a Visual Studio C++ solution with 3 projects: one contains all classes

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.