title: Is there any way to prevent override/overwrite of functions/variables in singleton instance?
body: <p>Consider this pseudo code:</p>
  
  <pre class="lang-js prettyprint-override"><code>(function(window){
     var options = { /*where everything goes */ };
  
     var instance = (function(options){
         for (var i in options){
         if (options.hasOwnProperty(i)){
           this[i] = options[i];
         }
       }
     })(options);
  
     instance.callbacks = function(cb){
       //...
     }
  
     instance.is_allowed = function()
      //... checks, return boolean
     }
  
     window.instance = instance;
  })(this);
  </code></pre>
  
  <p>If anyone ever wanted to manipulate this code (a malicious user for example), he would rewrite the <code>is_allowed</code> function with his own, for example, using the address bar (he doesn't have firebug, who knows). </p>
  
  <pre><code>javascript:(function(){ window.instance.is_allowed = function(){ return true; } })();
  </code></pre>
  
  <p>This is a naive example, but that's the point, anything in Javascript can be overwritten. </p>
  
  <p>I know in es5 we have the Object.defineProperty so you can set:</p>
  
  <pre class="lang-js prettyprint-override"><code>// being explicit
  Object.defineProperty(instance, "is_allowed", {
    enumerable: false,
    configurable: false,
    writable: false,
    value: function(){
      // do checks
    }    
  });
  </code></pre>
  
  <p>Actually, what is BEST in this sense is to use <code>Object.freeze(instance)</code> or <code>Object.seal(instance)</code> instead of <code>Object.defineProperty</code>, since the later can be called again with <code>writable: false</code> (silly huh?)</p>
  
  <p>Is there ANY way that it work in old browsers (namely IE6-8) without too much hassle? If it's impossible, then I'll just shrug and move on.</p>