JavaScript Equivalent Of PHP __call
<p>In PHP you can detect when a method is called even when it doesn't exist using the "magic" <code>__call</code> function.</p>

<pre><code>public function __call($methodName, $args)
{
    // do something
}
</code></pre>

<p>You can call any method and the name and arguments are passed to this magic catch-all.</p>

<p>Is there a similar technique in JavaScript that would allow any method to be called even if it actually didn't exist on the object?</p>

<pre><code>var foo = (function () {
    return {
         __call: function (name, args) { // NOT REAL CODE
             alert(name); // "nonExistent"
         }
    }
}());

foo.nonExistent();
</code></pre>
