How to write a mock object that will never throw "Cannot read property '**' of undefined'" in JavaScript
<p>With the intention to write unit tests, I want to pass an object to my function that mocks any possible property - <strong>Note: not a function property</strong>. </p>

<p>When I have a function like this:</p>

<pre><code>function someFunc (config){
    var something = config.params.innerParams;
}
</code></pre>

<p>when called <code>someFunc({})</code> it will throw <code>Cannot read property 'innerParams' of undefined'</code>.</p>

<p>If there are many recursive properties in <code>config</code>, mocking it may be very time consuming. Is there a way to write a "mock" object that I can pass to my function to mimic any structure? It may assign undefined to all properties <strong>at the time of access</strong>, like this:</p>

<pre><code>var magic = new Magic(); //magical mock created
var a1 = magic.something; //undefined;
var a2 = magic.something.innerSomething; //undefined
var a3 = magic.something.innerSomething.farAwaySomething; //undefined
</code></pre>

<p>All I want is to avoid <code>Cannot read property '*' of undefined'</code> being thrown. </p>