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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:08:45+00:00 2026-06-07T20:08:45+00:00

Is there any method that invokes a function but sets the context this to

  • 0

Is there any method that invokes a function but sets the context this to the “default” value that it has when I invoke the function by doing fn()?

This method should accept an array and pass the single elements as arguments to the function, much like apply() does:

emitter = new EventEmitter();
args = ['foo', 'bar'];

// This is the desired result:
emitter.emit('event', args[0], args[1], ...);

// I can do this using apply, but need to set the context right
emitter.emit.apply(emitter, 'event', args);

// How can I trim the context from this?
emitter.emit.???('event', args);

EDIT: To clarify this, I do care about the value that this will have inside the called function – it needs to be the “normal” context it has when doing emitter.emit(), not the global object or anything else. Otherwise, this will break things sometimes.

  • 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-07T20:08:49+00:00Added an answer on June 7, 2026 at 8:08 pm

    Just set the first parameter to the global object (i.e. window in a browser)

    In ES3 browsers you could pass null instead and it would be automatically be changed to the global object, but that behaviour has been removed in the ES5 specifications.


    EDIT it sounds like you just need a new function:

    EventEmitter.prototype.emitArgs = function(event, args) {
        this.emit.apply(this, [event].concat(args));
    }
    

    at which point you can just call:

    emitter.emitArgs('event', args);
    

    (EDIT thanks to @Esalija for [].concat)

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

Sidebar

Related Questions

Is there any other method that is faster than doing like this? private void
Is there any tool or method that can speed up this process? For instance
I found that there's a clearRect() method, but can't find any to clear an
Is there any method that can help me track internet usage by application? I
In Ruby is there any method that lists all the global variables available at
Is there any method so that I can stop syncing to gmail. I want
There is any command line or .NET method that runs a process in the
I want to know that is there any better method to do : var
Are there any plugin for eclipse that allows to show only one method from
I have searched through internet & found that there are no any direct method

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.