title: handle a function that returns a promise or a null value
body: <p>I have defined a function as following :</p>
  <pre><code>function getCurrentComponent(){
      if($rootRouter._currentInstruction){
          return $rootRouter.recognize($rootRouter._currentInstruction.urlPath).then(function (data) {
              return data.component.componentType;
          });
      }else{
          return null;
      }
  }
  </code></pre>
  <p>To call this function I did as following :</p>
  <pre><code>factory.getCurrentComponent().then(function (data) {
      ...
  });
  </code></pre>
  <p>The problem is when the <code>getCurrentComponent</code> function returns a null value, the following error is generated :</p>
  <blockquote>
  <p>Cannot read property 'then' of null</p>
  </blockquote>
  <p>How can I solve this ?</p>
  <h1>Edit:</h1>
  <p>I forgot to say that I'm limited to use ES5, so I can't work with the object <code>Promise</code></p>