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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:23:11+00:00 2026-05-29T08:23:11+00:00

I have an object for each room I’m joining with Strophe. This object contains

  • 0

I have an object for each room I’m joining with Strophe. This object contains a function for handling presence stanzas for this particular room.

function Room(name, someData)
    this.name = name;
    this.someData = someData;

    this.presenceHandler = function(presence) {
        console.log(this.name, this.someData);
    }

    this.join = function() {
        connection.addHandler(this.presenceHandler,null,"presence",null,null,this.name);
        connection.send(/*presence*/);
    }
}

var connection = new Strophe.Connection(/*http-bind*/);
var mainRoom = new Room("main", {foo: "bar"});
mainRoom.join();

But when the mainRoom.presenceHandler() function is called by an stanza by Strophe, this in the function refers to the stanza itself and not to mainRoom anymore, so I cannot access the attributes from mainRoom.

Could you tell me, how I can access the attributes of the room object from within the presenceHandler function?

  • 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-29T08:23:11+00:00Added an answer on May 29, 2026 at 8:23 am
            this.join = function() {
        connection.addHandler(this.presenceHandler,null,"presence",null,null,this.name);
        connection.send(/*presence*/);
    }
    

    Replace above code with this

            var thiss=this;
        this.join = function() {
        connection.addHandler(function(presence)             
        {thiss.presenceHandler(presence);},null,"presence",null,null,this.name);
        connection.send(/*presence*/);
    }
    

    note the closures for the handler

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

Sidebar

Related Questions

I have this ListBox which is bound to an ObservableCollection. Each object in the
I have an object that contains a collection of items, each item being another
I have an application where for each object the user can specify his own
I currently have a collection with a HasChanges property on it (each object in
I have a list of objects. Each object has an integer quantity and a
Does a new SessionFactor y and Session object have to be created for each
I have a database populated with 1 million objects. Each object has a 'tags'
I have a tree that consists of several objects, where each object has a
I have two Collection objects, I want to associate each object of these two
I have parsed XML file into objects, in which each object has a 1:1

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.