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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:51:32+00:00 2026-05-30T15:51:32+00:00

If you see something here that you think could be improved upon, please let

  • 0

If you see something here that you think could be improved upon, please let me know!

The Problem: I’m trying to accomplish a basic structure of processing some Json data through a mootools class. What I’m currently running into is when I call ‘this.processObj’ I receive ‘processObj is not defined’

Code:

this.runSomeJson= new Class({

    Implements: [Options, Events],

    options: {
        contentInfo: false,
    },
    initialize: function(element, options) {
        this.element = document.id(element);
        if (!this.element) return;
        this.setOptions(options);
        this.setBasicInfo();
    },
    setBasicInfo: function () {
        var callThis = 'somegenericurl';
        this.getObj(callThis);
    },
    getObj: function (callThis) {
        var jsonReq = new Request.JSON({
          method: 'get',
          url: callThis,
          onRequest: function () {
            console.log('Loading: ' + callThis);
          },
          onComplete: function(thisObj){
            //console.log(thisObj);
            this.processObj(thisObj);
          }
        }).send();  
    },
    processObj: function (thisObj) {
        console.log('in process..');
    },
});
  • 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-30T15:51:34+00:00Added an answer on May 30, 2026 at 3:51 pm

    the binding of this in an onComplete of a request is the Request Instance itself, not your original scope.

    there are 3 patterns you can use.

    1. saving a reference

    getObj: function (callThis) {
        var self = this;
        new Request.JSON({
          method: 'get',
          url: callThis,
          onRequest: function () {
            console.log('Loading: ' + callThis);
          },
          onComplete: function(thisObj){
            // call it on the self reference
            self.processObj(thisObj);
          }
        }).send();  
    },
    

    2. binding the anonymous function

    you can use the function.bind decorator to change scope within the callback:

    getObj: function (callThis) {
        new Request.JSON({
          method: 'get',
          url: callThis,
          onRequest: function () {
            console.log('Loading: ' + callThis);
          },
          onComplete: function(thisObj){
            //console.log(thisObj);
            this.processObj(thisObj);
          }.bind(this) // change scope, inner this becomes the outer this as well.
        }).send();  
    },
    

    3. move to the method on the class and bind directly

    this skips the anon function creation.

    getObj: function (callThis) {
        new Request.JSON({
          method: 'get',
          url: callThis,
          onRequest: function () {
            console.log('Loading: ' + callThis);
          },
          onComplete: this.processObj.bind(this)          
        }).send();  
    },
    

    in terms of preference: I’d choose #1 as it has the smallest performance footprint, it is the preferred mootools way [tm]. then probably #3 for best code organisation.

    there is a 4th way in conjunction with the binds class mutator from mootools-more but let’s not do that 🙂

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

Sidebar

Related Questions

I'm trying to think an interface for a time-keeping system that will let users
No doubt I'm missing something really simple here but I just can't see the
I often see something like that: something.property|escape something is an object, property is it's
I use MVVM architecture to decouple my application. That is, you often see something
I'm trying to use Boost regex to see if something has an integer in
Could someone prove to me that the advice given here (copied below) regarding removing
This question is very similar to that posed here . My problem is that
I've got a Subsonic query that isn't returning any values. I think the problem
Do you prefer to see something like t_byte* (with typedef unsigned char t_byte )
it's common to see something like this in code, hopefully only during development: //XXX:

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.