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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:30:42+00:00 2026-05-27T07:30:42+00:00

I have a Javascript object literal: var Toolbar = { init: function(toolbar) { this.Bar

  • 0

I have a Javascript object literal:

var Toolbar = {

    init: function(toolbar) {
        this.Bar = $(toolbar); // scope is Toolbar object literal

        this.Bar.find('clearButton').click(function() {
            this.trigger('clear'); // doesn't work!
            this.Bar.trigger('clear'); // works!
    }
}

Toolbar.init($('div.toolbar'));
Toolbar.bind('clear', function() { ... }); // doesn't work!
Toolbar.Bar.bind('clear', function() { ... }); // works!

I’d like to be able to trigger the clear event on the Toolbar object literal rather than the toolbar DOM object referenced in the literal. Is this possible, and if so, how would I do it?

  • 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-27T07:30:43+00:00Added an answer on May 27, 2026 at 7:30 am

    This should work:

    var Toolbar = {
    
        init: function(toolbar) {
            this.Bar = $(toolbar); // scope is Toolbar object literal
    
            this.Bar.find('.clearButton').click($.proxy(function() {
                $(this).trigger('clear'); // should work now
                this.Bar.trigger('clear'); // still works
            }, this));
        }
    };
    
    Toolbar.init($('div.toolbar'));
    
    $(Toolbar).bind('clear', function() { 
        console.log('Toolbar'); 
    }); // should work now
    
    Toolbar.Bar.bind('clear', function() { 
        console.log('Toolbar.Bar'); 
    }); // still works
    
    1. You need to maintain the this reference in the click function. I used $.proxy; some folks use var self = this;

    2. Toolbar is not a jQuery object so it should be wrapped in $() to access jQuery’s functions. Also wrap the this that refers to a Toolbar instance in the click function.

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

Sidebar

Related Questions

Let's say I have a JavaScript object: function a(){ var A = []; this.length
I have a javascript that does this (http is your XMLHttpRequest object) var r
I have a Javascript object the following: function extraFields(id) { this.numActiveFields = 0; ...
I have the following javascript object literal (excerpt) var foo = {hello[35]:100,goodbye[45]:42}; I have
HI, I have a JavaScript program that's written with object literal syntax: var MyJsProgram
I currently have a Javascript function that uses a string to reference an object
I have many JS object literal files in my code. In a JS function
Suppose I have a Javascript object which is initialized var letters = {q:0, t:0,
If I have a JavaScript object such as: var list = { you: 100,
I have two object literals: var animal = { eat: function() { console.log(eating...); }

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.