By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,598 Members | 1,894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,598 IT Pros & Developers. It's quick & easy.

Is this at all possible???

P: n/a
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

Oct 13 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On 13 Oct 2005 13:49:12 -0700, sn****@mxlogic.com wrote:
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.
Oct 13 '05 #2

P: n/a
Sorry... you've lost me. What does that do exactly?

Steve

Oct 13 '05 #3

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

-Jeremy

sn****@mxlogic.com wrote:
Sorry... you've lost me. What does that do exactly?

Steve

Oct 13 '05 #4

P: n/a
You could also try wrapping the function using closures:-

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

Oct 14 '05 #5

P: n/a
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

Oct 14 '05 #6

P: n/a
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

Oct 14 '05 #7

P: n/a
sn****@mxlogic.com wrote:
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?


Well, the short answer is YES. You can do this, in a few different ways.

The approach to use really depends on the larger context in which
you are performming the work.

Probably the easiest is to simply rename the existing function,
and make a new function with the old name.

This new function can do anything you want , including calling
a function before and after calling the old function.

--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> Internet Programming since 1994 <>=-- DHTML NSAPI TCP/IP
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Oct 14 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.