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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:13:43+00:00 2026-06-10T17:13:43+00:00

i need to detect when some third party function returns and then execute my

  • 0

i need to “detect” when some third party function returns and then execute my own function.

example: some function i didn’t write

function foo(params1){
  console.log(params1);
}

my function:

function bar(params2){
  console.log(params2);
}

i need that whenever foo is called, it somehow calls bar immediately !
i tried going this way:

foo = function(params1){
  console.log(params1);
  bar(params2);
}

meaning i “overwrite” foo .. but sometimes (always), foo code is too lengthy + passing params2 (minor) problem.
I tried desperate attempts with prototype and so .. but then i figured i need some support on this.

i also tried this: (but)

var tmp = foo;
foo = function(params1) {
  tmp(params1);
  bar(params2);
}

Same problem here, the caller will call foo(params1) thus bar won’t “find” params2.


I need this to make something like an “event handler”.
The third party function makes some ajax calls, acts on the DOM, i immediately take action.
Is there a neat way of doing this? i hope this is interesting. Thanks.
ps: i though about making params2 global, but i still need an “original” solution 🙂

As for the use of params2, let’s say i want to use different params for every function i want to hook.

examples:

var tmp = foo_1;
foo_1 = function(params1) {
  tmp(params1);
  bar(params2);
}

tmp = foo_2;
foo_2 = function(params1) {
  tmp(params1);
  bar(params3);
}
//etc..
  • 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-10T17:13:44+00:00Added an answer on June 10, 2026 at 5:13 pm

    Maybe you should use a simple pubSub system to get notified when foo is called. This will decouple your call of bar from foo.

    (function(){
      var footmp = foo;
    
       foo = function(){
         var result = footmp.apply(this, arguments);
         PubSub.publish('fireBar');
         return result;
      }
    })()
    
    PubSub.subscribe( 'fireBar', function(){
     // try to figure out whats params2
     bar(params2)
    } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to run some code, for example, to detect browser prefered languages and
I need to detect if text input was processed by keyboard or some auto
i need to detect the strength of the shake. I have to move some
I need to detect when some of the fields of certain model have changed
I need to detect page to do some styling on a website, right now
I need detect words that separate with space in a text. for example my
I need to detect if some application is currently running in full screen mode.
I need to detect the language version of VS and do some action depending
I am writing some C# code and I need to detect if a specific
I am drawing and animating some objects using GDI. I need to detect a

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.