I have a website with a <script> tag
<script id='text1' type='text/javascript'></script>
that I insert some javascript code into from a <textarea>
<div id="text2">
<textarea class="text3"></textarea>
</div>
while executing some javascript
// get text from text area
obj = document.getElementById('text2').getElementsByClassName('text3');
var text = obj[0].value;
// assign to script tag
obj = document.getElementById('text1');
obj.text = text;
and on a button click it executes a function in a namespace from the <textarea> code
var namespace1 = {};
(function(context) {
context.getGameName = function() {
return ('text');
};
})(namespace1);
Everything works just fine, but if I attempt to change the text in the <textarea> and update the contents of the <script> tag, I can see in the console that the contents in the DOM are being updated, but when executing the code again on the button click, the old code is executed, not the new.
How can I update the javascript and execute the new version of a function with the same name?
[<>]toolbar button). It's hard to tell what code is running where. Fundamentally, once code is parsed and run, any enduring effects it has (such as creating functions) become part of the current state of the JavaScript environment. Unlike (say) CSS rules, removing that script doesn't remove the effects it had.