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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:26:37+00:00 2026-05-27T08:26:37+00:00

Is it possible to bind a function to another function on invoke? So for

  • 0

Is it possible to bind a function to another function on invoke? So for example, it would go something like this:

function a(){...}
function b(){...}
b.bind("onInvoke","a");

So when b is called, a is also automatically called.


EDIT: OK OK, to clarify, this is not a question on chaining. The idea is to find an elegant way to do event binding. Observe the normal “non-elegant” way with normal function call-back:

function handler(){...}
function caller1(){handler(); ...}
function caller2(){handler(); ...}
function caller2(){handler(); ...}
// More callers all over your website everywhere else

That works right? But what if I have caller all over the place? It’s hard to organize or change things.

Now observe the superior solution! (If one exist)

function handler(){...}
// Caller make no reference to handler on creation
function caller1(){...}
function caller2(){...}
function caller3(){...}
// Caller function are still all over the place, all over your website
// Event handler registered later in one location here, doesn't matter where they are phsically
caller1.bind("onInvoke",handler);
caller2.bind("onInvoke",handler);
caller3.bind("onInvoke",handler);

So very much like your normal HTML – JQuery event registration. You don’t write onClick on every image the user might click on (which are all over the place), it would be way too troublesome to organize that! You just write one simple

 $("img").bind("onClick",click_handler);

for your entire site. This is the jist of what I am looking for, except for JS functions.

I hope that clarify things.


EDIT 2: Need to work with IE7!!! JavaScript 1.8.5 is great and everything, but nothing support it right now.

  • 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-27T08:26:38+00:00Added an answer on May 27, 2026 at 8:26 am

    You can do that with an aspect-oriented approach.
    Here is a simple example:

    Attach call to a() to function b():

    var _b = b;
    b = function(){
       _b();
       a();
    }
    

    Now call b():

    b();
    

    See it in action here: http://jsfiddle.net/eZ9wJ/

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

Sidebar

Related Questions

Basically I'd like to bind function A to all inputs. Something like this: $('input').bind('change',
I want to bind a function to a right click. Is this possible with
Is it possible to bind an additional resource string to another attribute within a
would it be possible to bind a Java application to a Cocoa graphical interface?
It's possible to implement INotifyCollectionChanged or other interface like IObservable to enable to bind
Assuming it's possible, how would one pass arguments by reference to a variadic function
Is it possible to use a :selector with the following in jQuery? $('.galler_attr').bind('click', function()
with the following three lines: $( .thumb ).bind( mousedown, function() { $('.thumb').not(this).unbind('mouseenter mouseleave'); });
Is it possible to bind event handlers (for example, on mouseup) to the document
In excel 2000, is it possible to bind a vba function to be executed

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.