javascript - add additional code to the existing function -
my title can misleading because might have chosen poor words describe there problem.
i have 1 constructor has many methods. object created constructor passed around other methods of , constructors can add together more methods object.
my question want execute 1 function phone call has executed methods whenever executed. how can accomplish this?
for example:
function foo(){ this.method1=function(){} this.method2=function(){} } function run_this(){} now, want add together method1 , method2, run_this should executed them after running method before returning is, if phone call this.method1 object created foo, should following:
this.method() run_this() note: please don't suggest adding function executed within method phone call because said passed around various other objects can assign other functions , want every function assigned execute function call.
try creating proxy instance of foo wrapps method1 , method2.
function fooproxy(foo){ this.method1=function(){ var result = foo.method1(); run_this(); homecoming result; } this.method2=function(){ var result = foo.method2(); run_this(); homecoming result; } } function run_this(){} var proxy = new fooproxy(somefoo); javascript
No comments:
Post a Comment