[英]How to add a callback function to an existing javascript function without adding code to the function?
Let say I have foo(). 假设我有foo()。 Is there a way to execute bar() after foo() without modifying foo()?
有没有办法在foo()之后执行bar()而不修改foo()?
foo(){ /* logic */}
bar(){ /* more logic *}
afterEvent1AlwaysExecute2(foo,bar);
Thank you! 谢谢! any non-jquery or jquery comments are appreciated :)
任何非jquery或jquery评论赞赏:)
You can do it without adding code to foo
, by reassigning the name foo
: 您可以通过重新分配名称
foo
而无需向foo
添加代码来执行此操作:
var original_foo = foo;
var foo = function() { original_foo(); bar(); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.