Javascript object used as parameter becomes undefined
<p>I am designing a web-based Choose Your Own Adventure game using JavaScript and jQuery, and am running into a problem with one of my functions. The basic structure is like this:</p>

<pre><code>//leftSide, rightSide, thirdOption defined up here

var exampleScene = {
    sceneText: "&lt;p&gt;Some narrative text&lt;/p&gt;",
    optionNames: ["Go Left", "Go Right", "A Third Option"],
    linkedScenes: [leftSide, rightSide, thirdOption]
};

function fillBox (scene) {
    $("#textBox &gt; *").remove();
    $("#textBox").append($.parseHTML(scene.sceneText));
    promptPlayer(scene);
}

function promptPlayer (scene) {
    for (i = 0; i &lt; scene.linkedScenes.length; i++) {
        $("#input &gt; ol").append("&lt;li&gt;&lt;/li&gt;");
        $("#input &gt; ol &gt; li").last().text(scene.optionNames[i]);
        $("#input &gt; ol &gt; li").last().click(function () {
            fillBox(scene.linkedScenes[i]);
        });
    }
}
</code></pre>

<p>The idea is to show the text of a "Scene" object in the output area, and generate clickable options in an input area. The info for the options is drawn from the linkedScenes property of the "Scene" object. However, the reference to the linkedScene property becomes undefined when it is used as an argument in the fillBox function.</p>

<p>I have verified using console.log() that it is defined while in the promptPlayer function. I have also tried instead pushing scene.linkedScenes[i] into a global array and using its indices as the argument, but this also becomes undefined.</p>

<p>I am truly stuck here, and any help would be greatly appreciated. I am still learning JavaScript and jQuery, so any links to resources that would help clear up these sorts of issues on my own in the future would also be greatly appreciated. Thanks!</p>