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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:42:09+00:00 2026-06-01T17:42:09+00:00

I am trying to write server side for my web application using Node.js. The

  • 0

I am trying to write server side for my web application using Node.js. The following code is extracted to simulate the situation. Problem is that the application crashes when trying to access this.actions.length in the actionExecuted “method”. The property this.actions is undefined there (this == {} within the scope) even it was defined in the “constructor” (the Request function itself). How to make the actions property accessible from other “methods” as well?

var occ = {
    exampleAction: function(args, cl, cb)
    {
        // ...

        cb('exampleAction', ['some', 'results']);
    },

    respond: function()
    {
        console.log('Successfully handled actions.');
    }
};

Request = function(cl, acts)
{
    this.client = cl;
    this.actions = [];
    this.responses = [];

    // distribute actions
    for (var i in acts)
    {
        if (acts[i][1].error == undefined)
        {
            this.actions.push(acts[i]);
            occ[acts[i][0]](acts[i][1], this.client, this.actionExecuted);
        }
        else
            // such an action already containing error is already handled,
            // so let's pass it directly to the responses
            this.responses.push(acts[i]);
    }
}

Request.prototype.checkExecutionStatus = function()
{
    // if all actions are handled, send data to the client
    if (this.actions == [])
        occ.respond(client, data, stat, this);
};

Request.prototype.actionExecuted = function(action, results)
{
    // remove action from this.actions
    for (var i = 0; i < this.actions.length; ++i)
        if (this.actions[i][0] == action)
            this.actions.splice(i, 1);

    // and move it to responses
    this.responses.push([action, results]);
    this.checkExecutionStatus();
};

occ.Request = Request;

new occ.Request({}, [['exampleAction', []]]);
  • 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-01T17:42:10+00:00Added an answer on June 1, 2026 at 5:42 pm

    The problem is the way you are defining your callback. It’s called later so it loses context. You have to either create a closure or properly bind the this. To create a closure:

    var self = this;
    occ[acts[i][0]](acts[i][1], this.client, function() { self.actionExecuted(); });
    

    To bind to this:

    occ[acts[i][0]](acts[i][1], this.client, this.actionExecuted.bind(this));
    

    Either one should work.

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

Sidebar

Related Questions

I'm trying to write the server side of my android app that uses C2DM.
I'm trying to make a web app that will read in a server-side CSV
Developing server side code i finally got my eyes X-crossed trying to write -
I'm trying to write a client-server application in Java with an XML-based protocol. But
I'm trying to write a simple server in c that plays a two player
I am trying to write a java application connecting to server connection channel with
I'm trying to write an insert statement for a SQL Server table that inserts
I am trying to learn how to write more dynamic web sites that use
I want to convert my web application prototype (PHP server side) to a C++
I am (trying to) write a server-side daemon in c, and it accepts connections

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.