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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:08:27+00:00 2026-06-14T05:08:27+00:00

I have written an observer in javascript. You can trigger Events like this: ClassThatExtendsEvent.triggerEvent(‘EventName’,

  • 0

I have written an observer in javascript. You can trigger Events like this:

ClassThatExtendsEvent.triggerEvent('EventName', arg1, arg2, ..., argn)

There is a variable number of arguments, with the first argument being the event name. I do as well have subscribers, that are saved in a private property of my event class. They are getting called like this:

Event.prototype.triggerEvent = function() {

  var callbacks = this._events[eventName];      
  if(callbacks !== undefined) {
    for (var i = 0, l = callbacks.length; i < l; i++) {

      // I do not need the first argument here!!!
      callbacks[i].apply(callbacks[i], arguments);
    }
  }
}

However, the subscribers do know the event name, hence it could be ommitted. But I do not know, how to remove one argument from the list (as it’s not an array but seems to be some kind of object).

I also need to readd the event name, once it’s been deleted, because after notfiying the direct subscribers, a global event system kicks in. This global event system needs the name.

Hence the entire function looks like this:

Event.prototype.triggerEvent = function() {

  // First we deliver to direct subscribers
  var callbacks = this._events[eventName];      
  if(callbacks !== undefined) {
    for (var i = 0, l = callbacks.length; i < l; i++) {
      // I do NOT need the first argument here!!!
      callbacks[i].apply(callbacks[i], arguments);
    }
  }

  // Now we broadcast the event to the entire system

  // I DO need the first argument here!!!

  Facade.getInstance().broadcastEvent.apply(Facade.getInstance(), arguments);      

}

How would you implement this?

  • 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-14T05:08:28+00:00Added an answer on June 14, 2026 at 5:08 am

    you can “Borrow” the shift method from the Array() object like this:

    cache the shift method

    shift = [].shift;
    

    then use it to take off the first element of the arguments (since it’s just an array like object)

    var firstArg = shift.apply(arguments); //in case you need it
    .
    .
    .
    callbacks[i].apply(callbacks[i], arguments);
    

    and as @casablanca said,

    Many methods will work with anything that behaves like an array
    (numeric indices and a length property)

    the shift method is just one of them.

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

Sidebar

Related Questions

I have written this code in JavaScript and works perfectly fine when I include
have written this little class, which generates a UUID every time an object of
I have written this code inside a servlet to delete certain records from three
I have been wondering about this for a while. What if Magento has written
Have written all the code in a silverlight class library (dll) and linked this
I have found the following script which is apparently written using the javascript framework
This one is really making me pull my hair out. I have written a
I have written a bash script which installs a number of packages, however for
I have written a function that sorts a big scale of data. To test
I have written a java program generates lots of files (say txt files) in

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.