3

Let say I have foo(). Is there a way to execute bar() after foo() without modifying foo()?

foo(){ /* logic */}

bar(){ /* more logic *}

afterEvent1AlwaysExecute2(foo,bar);

Any non-jQuery or jQuery comments are appreciated :)

1
  • You could always wrap foo inside a new function which will call the old foo, and then call bar. Then you change the name of this new function to foo. As far as the outside world is concerned foo should work as expected, but secretly your replaced implementation will also call bar. Win! Commented Jul 19, 2012 at 1:14

1 Answer 1

9

You can do it without adding code to foo, by reassigning the name foo:

var original_foo = foo;
var foo = function() { original_foo(); bar(); }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.