title: Javascript: Checking if function exists in sibling frame before calling
body: <p>I have two frames in a window. Frame A and frame B. </p>
  
  <p>I want to call a function which is in frame A from frame B. To do this I use:</p>
  
  <pre><code> parent.frames['mainframe'].myfunction();
  </code></pre>
  
  <p>The catch is that the function may not actually exist in frame A.</p>
  
  <p>I want to check if it exists before calling. </p>
  
  <p>I tried this but got a JS error.</p>
  
  <pre><code>if ( typeof parent.frames['mainframe'].myfunction == 'function' ) { 
          //function_name is a function
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>TypeError: undefined is not a function
  </code></pre>
  
  <p>Update:</p>
  
  <p>You are all correct- the actual code I was running was typeof parent.frames['mainframe'].myfunction() with parenthesis. Sorry :/ What do I do about best answer?</p>