title: jquery run custom function after another is done
body: <p>I want to execute a custom function only after the previous custom function is completely done.</p>
  
  <p>I tried with promise, done and when but it's not working correctly. The fisrt function is not completely done when the second is executed...</p>
  
  <p>For example, I want to execute function1() then execute function2 only when function1 is done :</p>
  
  <pre><code>function1();
  function2();
  </code></pre>
  
  <p>I tried with this but it's not working at all :</p>
  
  <pre><code>promise(function1()).done(function2);
  </code></pre>
  
  <p>Here the script of my function1 :</p>
  
  <pre><code>function function1() {
  
      nbofslides = $('.Slide img').length;
      currentslide = 1;
  
      if ( nbofslides == currentslide) {
  
          if ( nbofslides &gt; 1) {
              for (i = 1 ; i &lt;= nbofslides ; i++) {
                  if (i == 1) {
                      $('.slider-pagination').append('&lt;li class="slider-page selected bgcolor2"&gt;&lt;/li&gt;');
                  } else {
                      $('.slider-pagination').append('&lt;li class="slider-page bgcolor2"&gt;&lt;/li&gt;');
                  }
              }
          }
  
          $('.iosSlider').iosSlider({
              responsiveSlideContainer: true,
              responsiveSlides: true,
              snapToChildren: true,
              desktopClickDrag: true,
              keyboardControls: true,
              infiniteSlider: true,
              navSlideSelector: true,
              autoSlide: false,
              navNextSelector: $('.slider-next'),
              navPrevSelector: $('.slider-prev'),
              navSlideSelector: $('.slider-pagination .slider-page'),
              onSlideChange: slideChange
              });
  
          var setHeight = $('.iosSlider .Slide:eq(0)').outerHeight(true);
          $('.iosSlider').css({
              height: setHeight
          });
  
          function slideChange(args) {
          $('.slider-pagination .slider-page').removeClass('selected');
          $('.slider-pagination .slider-page:eq(' + (args.currentSlideNumber - 1) + ')').addClass('selected');
          }
  
      }
      currentslide++;
  
  }
  </code></pre>