title: JavaScript function call/apply with string
body: <p>I just noticed that, when I want to pass string as <code>"this"</code>, the type cannot be obtained correctly inside a JavaScript function.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>var str = 'string value';
  if (typeof (str) == 'string') {
      alert('string outside');
  }
  
  var fn = function(s) {
      if (typeof (str) == 'string') {
          alert('string param');
      }
  
      if (typeof (this) == 'string') {
          alert('string this');
      }
      else {
          alert(typeof(this));
      }
  };
  
  fn.call(str, str);
  </code></pre>
  
  <p>I see 3 messages: <code>"string outside"</code>, <code>"string param"</code>, and <code>"object"</code>.</p>
  
  <p>My goal is to write an <code>"if"</code> statement that says <code>"this"</code> is string. Something like <code>if (typeof(this) == 'string')</code>. This one does not work, please point me to the correct statement that will work inside the function.</p>