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 ments are appreciated :)
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 ments are appreciated :)
Share Improve this question edited Nov 17, 2022 at 23:10 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jul 19, 2012 at 1:09 jdpubjdpub 312 bronze badges 1-
You could always wrap
foo
inside a new function which will call the oldfoo
, and then callbar
. Then you change the name of this new function tofoo
. As far as the outside world is concernedfoo
should work as expected, but secretly your replaced implementation will also callbar
. Win! – Anurag Commented Jul 19, 2012 at 1:14
1 Answer
Reset to default 9You can do it without adding code to foo
, by reassigning the name foo
:
var original_foo = foo;
var foo = function() { original_foo(); bar(); }
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745362888a4624441.html
评论列表(0条)