title: JavaScript - Equivalent of PHP Class self::
body: <p>So I've been searching on this because it's giving me a headache not being able to achieve this... And seems like there is no solution the way I expected to be.</p>
  
  <p>Let's assume we have a sample <code>PHP</code> class:</p>
  
  <pre><code>&lt;?php 
  
  class SampleClass {
  
      function doA() {
          echo 'Hello world';
      }
  
      function doB() {
  
          $sampleArray = ['Hey', 'You'];
  
          foreach( $sampleArray as $key =&gt; $value ) {
  
              self::doA();
  
          }
  
      }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>This code will echo <code>Hello World</code> two times because of the foreach loop. And thats good.</p>
  
  <p>Now I have this <code>script</code>:</p>
  
  <pre><code>function SectionHandler($appWrap) {
  
   this.appWrap = $appWrap;
  
   this.loading = function() {
      this.appWrap.addClass('section-loading').html("&lt;i class='fa fa-refresh fa-2x fa-spin'&gt;&lt;/i&gt;");
   }
  
   this.setError = function($info) {
      this.appWrap.addClass('section-error').html($info);
   }
  
   this.load = function($section) {
  
    var $fileCheck = $.get($section).success(function(){
      self.loading();
      self.load($section);
    }).fail(function(){
      self.setError('No se pudo cargar los datos especificados desde ' + $section + ' ;');
    });
  
   }
  
  }
  </code></pre>
  
  <p>I believe that <code>this.loading()</code> is no longer pointing to the main function because of the <code>$.get().success()</code> function. I do not know the real reason.</p>
  
  <p>The problem is that none of <code>this.loading(), this.load(), this.setError()</code> is working.</p>
  
  <p>So, how I do to point to the main function like I were using <code>PHP self::</code> function.?</p>
  
  <h3>-- EDIT --</h3>
  
  <p>As @Eclecticist pointed out the line <code>this.load($section);</code> will execute untill it fails or gets an error, I change the whole check to this:</p>
  
  <pre><code>var $fileCheck = $.get($section).done(function(response){
   self.appWrap.html(response);
  }).fail(function(){
   self.setError('No se pudo cargar los datos especificados desde ' + $section);
  });
  </code></pre>