How to prevent access to object properties that do not yet exist
<p>Often I have this situation:
<code>
var obj = { field: 2 };
</code></p>

<p>and in the code:
<code>
do_something( obj.fiel );  // note: field spelt wrong
</code></p>

<p>ie The property is incorrectly typed.  I want to detect these bugs as early as possible.</p>

<p>I wanted to seal the object, ie
<code>obj = Object.seal(obj);</code></p>

<p>But that only seems to prevent errors like <code>obj.fiel = 2;</code> and does not throw errors when the field is simply read.</p>

<p>Is there any way to lock the object down so any read access to missing properties is detected and thrown?</p>

<p>thanks,
Paul</p>

<p>EDIT: Further info about the situation</p>

<ol>
<li>Plain javascript, no compilers.</li>
<li>Libraries used by inexperienced programmers for math calc purposes.  I want to limit their errors.  I can spot a misspelt variable but they can't.</li>
<li>Want to detect as many errors as possible, as early as possible.  ie at compile time (best), at runtime with thrown error as soon as wrong spelling encountered (ok), or when analysing results and finding incorrect calculation outputs (very very bad).</li>
<li>Unit tests are not really an option as the purpose of the math is to discover new knowledge, thus the answers to the math is often not known in advance.  And again, inexperienced programmers so hard to teach them unit testing.</li>
</ol>
