How can I call an anonymous function (stored in string) with an argument in JavaScript?
<p>I have the following situation in JavaScript:</p>

<pre><code>&lt;a onclick="handleClick(this, {onSuccess : 'function() { alert(\'test\') }'});"&gt;Click&lt;/a&gt;
</code></pre>

<p>The <code>handleClick</code> function receives the second argument as a object with a <code>onSuccess</code> property containing the function definition...</p>

<p><strong>How do I call the <code>onSuccess</code> function (which is stored as string) -and- pass <code>otherObject</code> to that function? (jQuery solution also fine...)?</strong></p>

<p>This is what I've tried so far...</p>

<pre><code>function handleClick(element, options, otherObject) {
    options.onSuccess = 'function() {alert(\'test\')}';

    options.onSuccess(otherObject); //DOES NOT WORK
    eval(options.onSuccess)(otherObject); //DOES NOT WORK
}
</code></pre>
