Is this at all possible???

S

sneill

I've been mulling this over for a while and I'd welcome any thoughts on
the matter...

In Javascript a function is an object, so is it possible to "retrofit"
to the function object prototype some "event" (a call to another
function perhaps) that gets triggered when it is starting execution and
when it returns or ends?

Steve
 
J

Jim Ley

I've been mulling this over for a while and I'd welcome any thoughts on
the matter...

In Javascript a function is an object, so is it possible to "retrofit"
to the function object prototype some "event" (a call to another
function perhaps) that gets triggered when it is starting execution and
when it returns or ends?

not absolutely reliably, but you can generally do

func=eval((func+'').replace('{','{ callFunc();'));

Jim.
 
J

Jeremy

Converts function to a string representing its code; adds the call you
want to the beginning of said code; evaluates said code.

-Jeremy
 
B

Baconbutty

You could also try wrapping the function using closures:-

function Retrofit(mainFunc, eventFunc)
{
return function(){eventFunc(); mainFunc(); eventFunc();};
}
 
S

sneill

I suppose that might work, except the main function could have multiple
exit points.

So, as far as we know, there's nothing like "onEnter" or "onExit" for a
function object in JS?

Steve
 
S

sneill

I suppose that might work, except the main function could have multiple
exit points.

So, as far as we know, there's nothing like "onEnter" or "onExit" for a
function object in JS?

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,802
Messages
2,569,662
Members
45,432
Latest member
KetoMeltIngredients

Latest Threads

Top