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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:45:38+00:00 2026-06-15T11:45:38+00:00

I want to use the JavaScript .apply method to functions of a thrift compiled

  • 0

I want to use the JavaScript .apply method to functions of a thrift compiled for Node.js. The thrift .js file has code like this:

...
var NimbusClient = exports.Client = function(output, pClass) {
    this.output = output;
    this.pClass = pClass;
    this.seqid = 0;
    this._reqs = {};
};
NimbusClient.prototype = {};
NimbusClient.prototype.getClusterInfo = function(callback) {
    this.seqid += 1; // line where error is thrown [0]
    this._reqs[this.seqid] = callback;
    this.send_getClusterInfo();
};
...

My server file looks the following way:

var thrift = require('thrift')
    , nimbus = require('./Nimbus')
    , connection = thrift.createConnection('127.0.0.1', 6627)
    , client = thrift.createClient(nimbus, connection)
    , ... // server initiation etc

app.get('/nimbus/:command', function(req, res, next) {
    client[req.params.command](console.log); // direct call [1]
    client[req.params.command].apply(this, [console.log]); // apply call [2]
});

...

The direct call [1] returns the values as expected, but the apply call [2] always produces the following error in line [0]:

TypeError: Cannot set property 'NaN' of undefined

I tried several other scope parameters in [2]: null, nimbus, nimbus.Client, nimbus.Client.prototype, nimbus.Client.prototype[req.params.command] and client[req.params.command], all without success.

How can I call the apply method without changing the actual scope of the function called, so that it behaves exactly the same as it would if called in the direct way?

  • 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-15T11:45:40+00:00Added an answer on June 15, 2026 at 11:45 am

    Pointing the apply function back to the same function like this should retain the original scope.

    client[req.params.command].apply(client, [console.log]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use javascript / jquery to determine if an xml file exists.
I have an HTML file and I want to use javascript to call a
I want to use a javascript countdown function similar to this http://jsfiddle.net/Apnu2/6/ when a
I want to use a JavaScript file, lying in the root folder. How can
I'm coding up a page where I only want to use raw JavaScript code
I have a javascript file that looks like this: if (x > 0 &&
I want use javascript setInterval function to achieve a box rotate animate effect, I
I want to use javascript to detect if an element exists under the cursor
I want to use javascript to change all of the <option> tags to <a>
I want to use javascript in my webpage to print time such as 8:40

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.