title: How can I differentiate an object literal from other Javascript objects?
body: <p><strong>Update</strong>: I'm rephrasing this question, because the important point to me is identifying the object literal:</p>
  
  <p>How can I tell the difference between an object literal and any other Javascript object (e.g. a DOM node, a Date object, etc.)?  How can I write this function:</p>
  
  <pre><code>function f(x) {
      if (typeof x === 'object literal')
          console.log('Object literal!');
      else
          console.log('Something else!');
  }
  </code></pre>
  
  <p>So that it only prints <code>Object literal!</code> as a result of the first call below:</p>
  
  <pre><code>f({name: 'Tom'});
  f(function() {});
  f(new String('howdy'));
  f('hello');
  f(document);
  </code></pre>
  
  <hr>
  
  <p><strong>Original Question</strong></p>
  
  <p>I'm writing a Javascript function that is designed to accept an object literal, a string, or a DOM node as its argument.  It needs to handle each argument slightly differently, but at the moment I can't figure out how to differentiate between a DOM node and a plain old object literal.</p>
  
  <p>Here is a greatly simplified version of my function, along with a test for each kind of argument I need to handle:</p>
  
  <pre><code>function f(x) {
      if (typeof x == 'string')
          console.log('Got a string!');
      else if (typeof x == 'object')
          console.log('Got an object literal!');
      else
          console.log('Got a DOM node!');
  }
  
  f('hello');
  f({name: 'Tom'});
  f(document);
  </code></pre>
  
  <p>This code will log the same message for the second two calls.  I can't figure out what to include in the <code>else if</code> clause.  I've tried other variations like <code>x instanceof Object</code> that have the same effect.</p>
  
  <p>I understand that this might be bad API/code design on my part. Even if it is, I'd still like to know how to do this.</p>