Friday, October 9, 2009

JavaScript: Script-ably Rewriting a Function

I've seen numerous posts in forums in regards to the ability to access, and sometimes modify, the contents of a JavaScript function dynamically (using JavaScript itself of course). To respond "globally" to these questions, I've created a quick little demo, hosted on Svidgen: JavaScript: Script-ably Rewriting a Function.

I considered posting the code for a brief moment; but, the demo provides a relatively simple look at script-ably playing around with JavaScript functions. Accessing the "contents" of a JavaScript function is simple; but the entire function definition is returned. So, editing the function on the fly and "recompiling" it isn't perfectly straightforward, and it's best to just see the demo if you're interested.