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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:28:37+00:00 2026-06-17T00:28:37+00:00

I have this basic code: app.Modules.myModule = { init: function(){ this.bindEvents(); }, bindEvents: function(){

  • 0

I have this basic code:

app.Modules.myModule = {
    init: function(){
        this.bindEvents();
    },

    bindEvents: function(){
        app.Events.on('user:added', this.userAdded.call(this));
        this.username = $('#username');
    },

    userAdded: function(event, params){
        console.log(params);
        this.username.text(params.username);
    }
};

Now the problem I have, is that if I call this.userAdded as it is, then params doesn’t get passed on to the userAdded function. If I don’t use ‘call’ and just do this.userAdded, inside the userAdded function, then the context of ‘this’ is the jQuery event and not the ‘app.Modules.myModule’ like I need it to be.

So my question is, how can I keep the context of ‘this’ inside the userAdded function to the Object itself (myModule) and be able to pass it the params argument?

  • 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-17T00:28:39+00:00Added an answer on June 17, 2026 at 12:28 am

    if you define your module as a function, the context can be set to a variable upon instantiation. For example:

    app.Modules.myModule = function(){
    
        var context = this;
        context.init = function(){
            context.bindEvents();
        };
    
        context.bindEvents = function(){
            app.Events.on('user:added', context.userAdded);
            context.username = $('#username');
        };
    
        context.userAdded = function(event, params){
            console.log(params);
            context.username.text(params.username);
        } ;       
    };
    
    var module = new app.Modules.myModule();
    

    The context variable will now reference the context of the object, and can be used within the functions. Make sure that you use the “new” keyword when initializing the object.

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

Sidebar

Related Questions

I have this basic shopping list app where in the first view there are
Hi I have this basic random quote script, but I would like it to
I have a js.erb with this basic content: $(#currencies).html(<%= options_for_select([['Dollar', '$']])%>); And the html
So I have this page that has some basic custom tabs: http://demo.unlockedmanagement.com/users/view/2 * NOTE
I have this table, which can be seen as a basic custom gantt chart:
Basic C# syntax question: So I have this class public class BrandQuery<T> : Query<T>
i know this is basic but somehow i have been stuck here for some
I realize this is a basic question but I have searched online, been to
I'm a noob so this is probably basic stuff, but I have tried to
I am new to WCF so I think this is pretty basic. I have

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.