title: Overriding native function?
body: <p>The native <code>document.createElement()</code> is silly-stupid (it takes only a tag name and no attributes). How come I can't override it? How come this doesn't work? </p>
  
  <pre><code>var originalFunction = document.createElement;
  
  document.createElement = function(tag, attributes) {
      var element = originalFunction(tag);
  
      if (attributes) {
          for (var attribute in attributes) {
              element.setAttribute(attribute, attributes[attribute]);
          }
      }
  
      return element;
  };
  </code></pre>
  
  <p>The problem is that browsers blow up when you try to replace a native function. Since <code>document</code> is not a JavaScript primitive, you can't create a prototype for it either. WTF.</p>