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

  • Home
  • SEARCH
  • 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 6722481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:27:09+00:00 2026-05-26T09:27:09+00:00

I have a javascript class declared as shown below.. My problem is the aonymous

  • 0

I have a javascript class declared as shown below.. My problem is the aonymous function does not see the scope of the class. I can not reference the bb_obj from within the ajax call load callback..

Is there a way to do this?

Thanks in advance..

dojo.declare("sop.quote", null,
{
   bb_obj : new Object,

   stage1 : function()
   {
      dojo.xhrPost(
      {
         url      :  'go/module_service/transport.php',
         content  :  this.bb_obj,
         handleAs :  'xml',
         load     :  function(xml)
         {
            var status  = xml.getElementsByTagName("STATUS")[0].childNodes[0].nodeValue;
            var message = xml.getElementsByTagName("MESSAGE")[0].childNodes[0].nodeValue; 

            this.bb_obj.message = message;
         },
         error    : function()
         {
         }
      }
   }
}
  • 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-26T09:27:09+00:00Added an answer on May 26, 2026 at 9:27 am

    this inside a XHR callback function refers to the XHR object. The only way to refer to bb_obj is by directly referring to the created object, in the same scope as the function. Because objects are passed by reference, the code below works as intended.

    Note to avoid confusion, I’ve declared the object using var bb_obj_obj={}. The bb_obj property refers to bb_obj_obj:

    • bb_obj_obj.message is changed
    • bb_obj points to bb_obj_obj, hence bb_obj.message refers to the same variable

    Code:

    var bb_obj_obj = {}; //new Object
    dojo.declare("sop.quote", null,
    {
       bb_obj : bb_obj_obj,
    
       stage1 : function()
       {
          dojo.xhrPost(
          {
             url      :  'go/module_service/transport.php',
             content  :  this.bb_obj,
             handleAs :  'xml',
             load     :  function(xml)
             {
                var status  = xml.getElementsByTagName("STATUS")[0].childNodes[0].nodeValue;
                var message = xml.getElementsByTagName("MESSAGE")[0].childNodes[0].nodeValue; 
    
                bb_obj_obj.message = message; //Without `this`
             },
             error    : function()
             {
             }
          }
       }
    }
    

    An alternative method consists of saving this in a variable, eg. $this:

    ...
    stage1 : function()
    {
        var $this = this;
        dojo.xhrPost({
         ...
         load     :  function(xml){
            var status  = xml.getElementsByTagName("STATUS")[0].childNodes[0].nodeValue;
            var message = xml.getElementsByTagName("MESSAGE")[0].childNodes[0].nodeValue; 
    
            $this.bb_obj.message = message; //Using `$this` instead of `this`
         },
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a javascript function (class) that takes a function reference as one paremter.
I have in my javascript these 2 functions classes: // product class function Product()
I have a javascript class that looks like this: function xyPoint(x, y) { this.
I have a JavaScript class that has a method: function someClass() { this.someMethod =
I have a javascript class like this: function Foo() { this.x = 5; this.y
I have following javascript class: var ImageGallery = function(arr) { var ImgArr = arr;
I have a Person javascript class like function Person(_name, _id, _salary){ this.Name = _name;
I have a Javascript class that contains a few functions and member objects: function
I have a JavaScript class that looks like this: function SomeFunction() { this.doSomething(function() {
I have a JavaScript class that I have made and put it into its

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.