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

The Archive Base Latest Questions

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

I’m trying to teach myself some better JS development practice, so I’m writing my

  • 0

I’m trying to teach myself some better JS development practice, so I’m writing my latest VLE widget in a JavaScript object wrapper.

var TutorGroupPoints = {
    URL: 'http://staff.curriculum.local/frog/rewards.php',
    CurrentUser: UWA.Environment.user.id,
    Groups: { },
    Sorted: [ ],

    init: function() {
        /* retrieve all of the groups from Frog and store them in a variable */
        Frog.API.get('groups.getAll',
        {
            'onSuccess': function (data) { this.Groups = data; },
            'onError': function(err) { alert(err); }
        });         
    },

    yearClick: function(year) {
        alert( this.Groups );

        for (var i = 0; i < this.Groups.length; i++) {

            if (this.Groups[i].name.indexOf(year) == 0 && this.Groups[i].name.indexOf('/Tp') != -1) {
                var arrayToPush = { 'id': this.Groups[i].id, 'name': this.Groups[i].name };
                this.Sorted.push(arrayToPush);
            }
        }
    }

};

widget.onLoad = function(){
    TutorGroupPoints.init();

    $('#nav li a').click(function() {
        TutorGroupPoints.yearClick($(this).attr("id"));
    });
}

The Frog.API call retrieves information about students/staff from our VLE (Virtual Learning Environment).

What I’m trying to do is store this information (retrieved in a variable called data) in a class-scope variable for use with other functions.

I thought I’d done that by declaring the Groups variable early on then using data = this.Groups, but then when I run the yearClick function, this.Groups simply appears as [object Object] where data alerts as loads of objects, i.e. [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object].

When I change Groups to [ ], the alert is entirely empty.

As such, I’m guessing that this is a scope problem. How can I store data from the Frog.API call in a variable which I can use with other functions? Previously I’ve just used functions, i.e. 'onSuccess': function (data) { someOtherFunction(data); }, but I don’t think that’s a very clean or practical way of doing it?

Thanks 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-09T16:09:04+00:00Added an answer on June 9, 2026 at 4:09 pm

    This is a common mistake. Your success callback, being a function, changes the this context that code executes in. So in your callback, this no longer points to the TutorGroupPoints object.

    Either cache a reference to the outer this outside the function…

    init: function() {
        var that = this; // <-- caching outer this
        Frog.API.get('groups.getAll', {
            'onSuccess': function (data) { that.Groups = data; },
            'onError': function(err) { alert(err); }
        });         
    }
    

    or bind a copy of it passed in via a closure, in this case an immediately-executing function

    init: function() {
        Frog.API.get('groups.getAll', {
            'onSuccess': (function(that) {
                 return function (data) { that.Groups = data; }
            })(this), // <-- passing reference to outer this
            'onError': function(err) { alert(err); }
        });         
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.