Subj : Re: question about javascript functions To : netscape.public.mozilla.jseng From : Béatrice Philippe Date : Tue Feb 08 2005 02:56 pm yes, your example is working ! but i'm trying to do this in my C++ application, using jsapi. And here is the problem... I'm interrested in modifying the body of an existing javascript function in its global object. So for the moment, i'm currently trying to delete my old function 'fun1' with 'js_deleteProperty()' in the global object, and then i create a new function with 'js_compileFunction()' method with the same name 'fun1'. If my application tries to call the new fun1 with 'js_callFunction..()', it's working. But if the new fun1 function is called by others existing functions, it crashes. I think when i try to delete a function fun1 with 'js_deleteProperty()', all functions that referenced this function fun1 are not notified about this change. They don't know fun1 was deleted and replaced by a new fun1 function. My question is: is there any way to change dynamically the body of an existing function in a C++ application, using jsapi ? or if no, is there any solution to create a new function that would replace the old one ? Thank you very much for your help. -- Béatrice Philippe-Derbez "Ludovic Delabre" a écrit dans le message de news: 4207f7cb$0$24720$626a14ce@news.free.fr... > Hello! > I'm not sure I understand what you want so ... Somethin' like this ? > (played with the jsshell) > > js> function myfun() { return "Original"; } > js> function fun1() { return myfun(); } > js> fun1() > Original > js> delete myfun > false > js> function myfun() { return "NewOne"; } > js> fun1() > NewOne > js> > > Ludovic. > > Béatrice Philippe wrote: >> Hello ! >> >> i'm currently trying to replace an old javascript function with a new one >> in the global object like this: >> 1) i create a new javascript function (say 'myfun') and compile it. >> 2) i delete the old property of the name 'myfun' >> 3) i add a new property with my new javascript function 'myfun' created >> and compile in step 1. >> >> these steps work well. But when i want to call a function 'fun1' that >> calls my new function 'myfun', it seems to be lost. >> am i forgetting something ? >> >> Thank you. >> >> example: >> " function fun1() { >> .... >> myfun(); //crash ! >> return; >> } >> >> function myfun(){ >> //this is my new function that replaced the old one with the same name. >> }" .