Can object literals be instantiated multiple times?
<p>I am writing a task app with javascript that uses object literals instead of constructors.  </p>

<p>A user clicks on specific elements on the page and a form receives typed "commands".  The system then prompts the user for arguments for the command.</p>

<p>It all works the first time around.  But if the user clicks on another element on the page and enters a command, the script runs TWICE!  It seems as though the object literals are stacking up.</p>

<p>Is that possible? </p>

<p><strong>Edit</strong>
I found that unbinding the form from any event handlers fixes the problem, using jQuery's <code>.unbind()</code>.  I guess my understanding of literals is poorer than I thought.  I don't understand how the form became bound to the literal in the first place.</p>

<p>I haven't posted code because I don't think the complicated app flow would help the question.  That is to say, the question isn't about MY code...but how object literals exist in javascript.  I am using them because I thought that only one instance was created.  Can more than one copy of a literal be created?</p>

<p>A user clicks on an elment on the page.  This may be a group name, topic name, or a task name.  Then they type a command in a command like form input at the bottom of the page.
When that form is submitted a few things happen: my <code>command</code> object lets a <code>received</code> property and runs a method <code>delegate()</code>.</p>

<pre><code>//handle command line submission
$(command.form).submit(function(event){
event.preventDefault();
command.received = $(command.line).val();
command.delegate();//sends the command to the appropriate taxonomy method
});
</code></pre>

<p><code>command.delegate()</code> checks if the command from the form input is one of the pre-defined commands allowed then calls a method <code>receive_command()</code> from one of three object literals, which represent if the element clicked by the user is a group, topic, or term.</p>

<pre><code>/*  engage the taxonomy object defined by selected item
    */
    delegate : function(){
        if(command.validates()){
            if(this.taxonomy == 'group'){group.receive_command();}
            if(this.taxonomy == 'topic'){topic.receive_command();}
            if(this.taxonomy == 'task'){task.receive_command();}
        }
    }
</code></pre>

<p>The <code>receive_command()</code> function for the topic object literal gets properties of the command object literal and determines which method to run based on which part of the two-part command cycle is current (part 1 shows a prompt, part 2 validates and runs the command).</p>

<pre><code>/*  command object sends retrieved commands to this function for constructive processing
*/
receive_command:function(){
    //read command name, call matching method
    //route command to second stage if set else to prompt method of called action if not

    if(topic.current_op){
        topic[topic.current_op].validate();
    }
    else{
        if(command.received.length &gt; 1){
        topic.current_op = command.received;
        }
        else{
        topic.current_op = topic.aliases[command.received];
        }
        topic[topic.current_op].prompt();
    }
},
</code></pre>

<p>When the user clicks the first element, prompting, then validating and running of the command works once.  Without page reload, when the user clicks another topic or the same topic again and adds another task, a blank task is addes without prompting for stage 2 of the command cycle.  When tracing things with <code>alert()</code>s placed at points in the code, it seems that submitting the form re-runs the previous commands as well as the current one.  The result is empty tasks being added to the list because stage one commands end with a press of the enter key, with no value in the command form, which the code reads as an empty task to insert into the database.</p>

<p>This information is complicated and over-wrought, but my question remains, how are multiple object literals instantiated multiple times?</p>
