title: Jquery check if var is a function and then call it
body: <p>I have a variable name that I pass into a plugin, but the variable is actually a function. 
  I use jquery $.isFunction to check if it is a function, and if it is, it should execute the function. </p>
  
  <p>But I can't seem to make it work, I put some examples in jsfiddle:<a href="http://jsfiddle.net/tZ6U9/8/" rel="nofollow noreferrer">http://jsfiddle.net/tZ6U9/8/</a></p>
  
  <p>But here is a sample code:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;a class="one" href="#"&gt;click&lt;/a&gt;&lt;br /&gt;
  &lt;a class="two" href="#"&gt;click&lt;/a&gt;&lt;br /&gt;
  &lt;a class="three" href="#"&gt;click&lt;/a&gt;&lt;br /&gt;
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>$(document).ready(function() {
  
  help = function(var1) {
      alert(var1);
  }
  
  function help2(var1) {
      alert(var1);
  }
  
  
  $('a.one').click(function() {
      var functionName = "help";
      if ($.isFunction([functionName])) {[functionName]("hello");
      } else {
          alert("not a function");
      }
  
      return false;
  });
  
  $('a.two').click(function() {
      var functionName = "help";
  
      if ($.isFunction(functionName)) {
          functionName("hello");
      } else {
          alert("not a function");
      }
      return false;
  });
  
  $('a.three').click(function() {
      var functionName = "help2";
  
      if ($.isFunction(functionName)) {
          functionName("hello");
      } else {
          alert("not a function");
      }
      return false;
  });
  
  $('a.four').click(function() {
      var functionName = "help2";
  
      if ($.isFunction([functionName])) {[functionName]("hello");
      } else {
          alert("not a function");
      }
      return false;
  });
  
  });​
  </code></pre>
  
  <p>As you can see, I tired a bunch of things, but all the wrong ones probably...
  I inspired some of them from: <a href="https://stackoverflow.com/questions/9604113/jquery-use-variable-as-function-name">jQuery - use variable as function name</a></p>
  
  <p><strong>Overall</strong>
  I'm passing a variable that has the same name as a function, using jquery to check if it is a function, if it is, it should execute the function.</p>
  
  <p>Thanks in advance for your help.</p>