Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
Accessing the name of the function when multiple functions are returned

I have a basic function, that can be called around my project using different names - tiger, lion, dog.

I'd like to access the name of the triggered name within the function its self.

For example:

I can run demo.tiger('Hello', {1:1}) and like to access the tiger name from within the trigger function.

Thanks

const demo = ({ }) => {

    function trigger (message, context) {

        console.log(message, context);

    }

    return {
        tiger: trigger,
        lion: trigger,
        dog: trigger
    }

}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As @Barmar suggested, you have to pass it through as an argument if you really want it.

const demo = () => {
  function trigger(message, context, caller) {
    console.log(message, context, caller);
  }

  return {
    tiger: (message, context) => trigger(message, context, 'tiger'),
    lion: (message, context) => trigger(message, context, 'lion'),
    dog: (message, context) => trigger(message, context, 'dog'),
  };
};

const x = demo();

x.tiger('a', { 1: 1 });
x.lion('a', { 1: 1 });
x.dog('a', { 1: 1 });

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!