title: Returning function from AngularJS factory
body: <p>I'm trying to understand what the purpose is of the return part of this AngularJS factory method means?</p>
  
  <pre><code>return {
      getMessages: getMessages
    };
  </code></pre>
  
  <p>What happens if we added a new method to this factory called getAnotherMessage(), would we need to update this return segment?  </p>
  
  <pre><code>myModule.factory('HelloWorld', function($q, $timeout) {
  
    var getMessages = function() {
      var deferred = $q.defer();
  
      $timeout(function() {
        deferred.resolve(['Hello', 'world!']);
      }, 2000);
  
      return deferred.promise;
    };
  
    return {
      getMessages: getMessages
    };
  
  });
  </code></pre>