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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:38:52+00:00 2026-05-25T18:38:52+00:00

Apologies if this isn’t a well constructed post – I’m writing it on my

  • 0

Apologies if this isn’t a well constructed post – I’m writing it on my phone because I’m in a meeting but can’t get this out of my head!

I’ve created an object, as follows:

   /* CLASS = "HPAnalysisObject" */

    /* CONSTRUCTOR */
    var HPAnalysisObject = {
        points_total: new Array(),

        getHPTotals: function(house_id, label) {
            for (var i = 1; i <= 26; i++) { 
                initial = String.fromCharCode(64 + i);
                Frog.API.get("users.search", {
                    "params": {"surname": initial, "group": house_id},
                    "onSuccess": this.addUsers
                });
            }

            alert(this.getArray());
        },

        getArray: function() {
            return this.points_total;
        },

        setArray: function(array) {
            alert(typeof(array));
        },

        addUsers: function(data) {
            array = new Array(this.getArray);

            for (var i = 0; i < data.length; i++) {
                if (data[i].profile.id == 200) {
                    array.push(data[i].id);
                }
            }

            this.setArray(array);
        }

    };

    widget.onLoad = function(){
        HPAnalysisObject.getHPTotals(10705, "eagles");
    }

The getArray function throws:

TypeError: not a function.

How do you, pseudo, initialise an empty array on init; put new items into that array with one function; then return the array with another?

EDIT: I HAVE OVERHAULED MY PSEUDO-CODE WITH THE ACTUAL CODE

  • 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-25T18:38:53+00:00Added an answer on May 25, 2026 at 6:38 pm
    "onSuccess": this.addUsers
    

    The problem is, once the addUsers function is assigned to this property, you’re losing the original this scope. One quick solution (that doesn’t require a lot of restructuring) is to use a Function.prototype.bind polyfill:

    "onSuccess": this.addUsers.bind(this)
    

    But, the more proper fix is to restructure your code to use a closure. With a closure, you can define functions that are “private” and bound to your object instance. Something in the lines of:

    var HPAnalysisObjectClass = (function () {
        var points_total = []; // "private"
    
        function addUsers(users) { // "private"
            // Use points_total, not this.points_total
        }
    
        return {
            addUsers: addUsers, // Make a "public" copy
    
            getHPTotals: function () {
                // ...
                    Frog.API.get("users.search", {
                        "params": {"surname": initial, "group": house_id},
                        "onSuccess": addUsers // not this.addUsers!
                    });
                // ...
            }
        };
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies up front, because this isn't a question but a solution - but it
Apologies if this was already asked but, I have had a look and can't
Apologies I can't post any code at this time cos I'm away from my
Apologies for probably simple question, I've read the docs and still can't get this
Apologies for the length of this post, but I think the background is necessary
Apologies if this is a slightly noob question, but looking to clarify my thoughts
Apologies if this is a dumb question but I'm trying to format a currency
Apologies for this question but I am a bit of a noob with Delphi.
Apologies for this basic question, but I am noob stumped. The below code works
I wasn't sure how to word the title to this well, apologies if the

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.