Dyanamic Execution of javascript code
<p>I have the following JavaScript:  </p>

<pre><code>var djs = function (ob) {

    return {
        remove: function () { //removes element
            if (is_array(ob)) {
                for (var i = 0; i &lt; ob.length; i++) 
                    ob[i].parentNode.removeChild(ob[i]);
            } else {
                ob.parentNode.removeChild(ob);
            }
        },
        empty: function () { //makes element empty
            if (is_array(ob)) {
                for (var i = 0; i &lt; ob.length; i++) 
                    ob[i].innerHTML = "";
            } else {
                ob.innerHTML = ""
            }
        },
        html: function (str) { //gets or sets innerHTML
            if (str) {
                if (is_array(ob)) {
                    for (var i = 0; i &lt; ob.length; i++) 
                       ob[i].innerHTML = str;
                } else {
                    ob.innerHTML = str;
                }
            } else {
                if (is_array(ob)) {
                    for (var i = 0; i &lt; ob.length; i++) 
                        rob += ob[i].innerHTML;
                    return rob;
                } else {
                    return ob.innerHTML;
                }
            }
        }
    }
}
</code></pre>

<p>Here every time I am checking whether <code>ob</code> is an array or not and executing code. I want to minimize this, like instead of:</p>

<pre><code>if (is_array(ob)) { 
    for (var i = 0; i &lt; ob.length; i++) 
        ob[i].parentNode.removeChild(ob[i]);
} else { 
    ob.parentNode.removeChild(ob); 
}
</code></pre>

<p>I want to use a function like, <code>doEval(ob,code,return)</code>, in this case,</p>

<pre><code>doEval(ob,"parentNode.removeChild("+ob+")",NULL);
</code></pre>

<p>"return" parameter will return if I specify any like <code>innerHTML</code>. Can any one help?</p>
