If I understand the question correctly you need to detect when some code is changed and render it on your page.
If you want to detect when an external code file is changed and use it on your application you can use HTML5 polling or even websockets.
The main problem is on JavaScript as it needs to be executed by the browser.
For code execution, I personally don't like eval()
, have you considered appending a script to your head or body?
The code is quite easy to follow:
var s = document.createElement("script");
s.type = "text/javascript";
s.id = "codetoexecute";
s.innerHTML = thecode;
$("head").remove("#codetoexecute");
http://jsfiddle.net/s6tkyxyh/1/
On the following example I am using a simple textarea to write some JavaScript. I have also added some variables to play around.
Please keep in Monday that this is a quite bad practise as you have to watch for memory leaks and also the scope of each function or variable. Using globally accessed methods and properties is recommended as debug will be too hard to follow.