I have HTML code that looks like this:
<body>
<label for="change0">What is your favorite number?</label>
<input type="text" id="change0" />
<div id="addStuff"></div>
<script src="scripts/main.js"></script>
</body>
And I have JS that looks like this:
/** @type {number} */
var counter = 1;
function doStuff(id) {
var thing = document.getElementById(id);
thing.addEventListener('change', doMoreStuff);
}
function doMoreStuff() {
counter++;
var addStuff = document.getElementById("addStuff");
var stuff = document.createElement("input");
stuff.id = "change" + counter;
stuff.type = "text";
addStuff.appendChild(stuff);
doStuff(stuff.id);
}
window.onload = function() {
/** @constant */
var SEED_ID = "change0"
doStuff(SEED_ID);
};
The doMoreStuff() function recursively calls the doStuff() function. Does JavaScript manage the memory properly, or am I doing this incorrectly?