A few days ago, I had asked a question that the function of the code Midway was modified through the execution of the execution script dynamically and I was told that completely forget about coming to the idea. I'm not sure why I think this is why. Give me an example:
& lt; Script & gt; Var display = function (msg) {warning (msg); } // Now, at the moment, the display () function is getting // one parameter and the user is alerting it to //. I'm going to modify the display () function to use eval () // now. ('Warning', 'document.write (')); // Now, the display () function writes its parameter as a document in the form of a document, as opposed to alerting it. & Lt; / Script & gt;
I know that this is a trivial example, but there must definitely be some experiment that can be achieved by being able to dynamically modify a function, some useful by yourself.
Although it can do what you need it, from now on for 6 months (or your code) Retaining person) "WTF ?!" Will happen!
If your use case is alert or write based on any condition, why do not you write two different functions? Another parameter that decides the output mode or passes in a function as a parameter that performs the actual output. Some, you know, small more on the sensible side .; -)