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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:03:24+00:00 2026-06-17T18:03:24+00:00

I have a namespace object on which I have defined some functions. One of

  • 0

I have a namespace object on which I have defined some functions. One of the functions is used to create a websocket session to a remote server.

ns.Session = function(url, config, callback){
   var ws = new WebSocket(url);
   ws.onmessage = function (e){
       if(login(e.data)){
           // This is the point at which I need to pass back the session object to callback
           callback(session):
       }
   }
   ....
}

In Javascript, as far as I know if someone invokes this function using ns.Session(....) then the this object will be ns. So, how do I get the instance of the “session” to send to the callback.
arguments.callee is deprecated as far as I know.

The whole reason I am doing it this way is that the session is not considered “usable” till the server confirms the login, so I don’t want to prematurely return the function object before it is actually connected and logged in. Hence the use of a callback. If there is a better way to achieve this, I am open to that too.

Session has a bunch of other inner functions like addHandler, sendData etc which I have not shown here for sake of brevity.

  • 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-17T18:03:25+00:00Added an answer on June 17, 2026 at 6:03 pm

    You can use pointer to function like this:

    ns.Session = function session(...) {
        // 'session' here points to your function, so you do
        callback(session); // like you wrote
        callback(ns.Session); // same effect if you don't change ns and ns.Session pointers
    }
    

    Also, I don’t see why you use the word “instance” in this case, because functions have only one instance. If you call it with the ‘new’ keyword, function creates new object from the function, and now there you can use “instance” word.

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

Sidebar

Related Questions

I have a helper assembly which includes a function to identify object types: namespace
I have an object gui_project which has an attribute .namespace , which is a
I have this line: @users = database['users'].find(:all).limit(10) it returns this object: <Mongo::Cursor:0x8759a858 namespace='app-development.users' @selector=:all
Say I have a template function in namespace A. I also have another namespace
I have a module Namespace/Search, which was installed when I got here. I took
I have some django apps which are versioned by app name. appv1 appv2 The
I have defined a class in C++ which holds an array of scalars of
i have written a library with some classes that make use of qt object
Have a homework assignment in which I'm supposed to create a vector of pointers
I want to create a UserSession model, which loads and saves the session ID

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.