title: Calling a function from another function with jquery
body: <p>I am trying to work out a function in javascript that iterates over about 10 functions.</p>
  
  <p>I have a function that creates service to call a json url into my functions. This communicates with a main function below which calls the service function with options to the corresponding url to use as the data to start the json request. Please see below;</p>
  
  <pre><code>var landp = {
  getCountryCode : function(){
      console.info('landp.GetCountryCode');
      return window.location.pathname.match(/\/([a-zA-Z]{2})/)[1].toLowerCase();
  },
  Service : {
      getBaseUrl : function(){
          console.info('landp.Service.GetBaseUrl');
          return sprintf("/%s/service", landp.getCountryCode())
      },
      callService : function(method, options){
          console.info('landp.Service.CallService');
          var url = sprintf("%s/%s", landp.Service.getBaseUrl(), method);
          $.ajax({
              url : url,
              method : 'GET',
              success : options.success,
              error : options.error
          })
      },
      getCategories : function(options){
          landp.Service.callService('category', options);
      },
      getCategoryId : function(options){
          landp.Service.callService('category/id/13', options);
      },
              getCategoryTopTen : function(options){
          landp.Service.callService('category/name/top-ten', options);
      },
      getSeeMoreItems : function(options){
          landp.Service.callService('see-more', options);
      },
      getPartnerOffers : function(options){
          landp.Service.callService('partner-offers', options);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This works okay as you can see getCategoryTopTen will call a url that holds the json data that I need to use to get the right items such as item.name, item.description etc etc. The code for this is below;</p>
  
  <pre><code>landp.Service.getCategoryTopTen({
      success : function(data){
          $('#header').after('&lt;div id="cat-sub-options"&gt;&lt;/div&gt;');
          $('#cat-sub-options').after('&lt;div class="flexslider"&gt;&lt;ul class="slides"&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div id="carousel-button" class="click"&gt;&lt;/div&gt;');            
          $.each(data[0].items, function(i, item){
          $('.flexslider .slides').append('&lt;li class=""&gt;&lt;h5&gt;' + i + '&lt;/h5&gt;&lt;a href="' + item.url + '"&gt;&lt;img src="' + item.imageLargeUrl + '" alt="' + item.name + ' image" /&gt;&lt;span&gt;' + item.name + '&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;');
      });
      },
      error : function(){
          console.log("Error getting categories");
      }
  })
  </code></pre>
  
  <p>As you can see the code works above and it pulls the right info into the correct elements etc. Currently there are about 10 categories such as;</p>
  
  <p>getCategoryTopTen
  getCategoryHistoryHeritage
  getCategoryWheretogo
  getCategoryShopping
  getCategorySportyPeople</p>
  
  <p>As you can see each one will be assigned to a category url in the json file.</p>
  
  <p>What I am trying to fix is how can I do the above for all the categories for instance where we have: landp.Service.getCategoryTopTen with the code below instead of writing itout on every category can I pass a variable instead to each function other wise I will have to do each of these json calls on every category.</p>
  
  <p>Any help would be much appreciated.</p>
  
  <p>Thanks,
  Mark</p>