title: How do you check if a JavaScript Object is a DOM Object?
body: <p>I'm trying to get:</p>
  
  <pre><code>document.createElement('div')  //=&gt; true
  {tagName: 'foobar something'}  //=&gt; false
  </code></pre>
  
  <p>In my own scripts, I used to just use this since I never needed <code>tagName</code> as a property:</p>
  
  <pre><code>if (!object.tagName) throw ...;
  </code></pre>
  
  <p>So for the second object, I came up with the following as a quick solution -- which mostly works. ;)</p>
  
  <p>The problem is, it depends on browsers enforcing read-only properties, which not all do.</p>
  
  <pre><code>function isDOM(obj) {
    var tag = obj.tagName;
    try {
      obj.tagName = '';  // Read-only for DOM, should throw exception
      obj.tagName = tag; // Restore for normal objects
      return false;
    } catch (e) {
      return true;
    }
  }
  </code></pre>
  
  <p>Is there a good substitute?</p>