title: Calling child method from parent in JavaScript
body: <p>I've a JavaScript class, and I'd like to override a parent method by creating a child class. However, I am struggling to work out how to call the child method from the context of the parent.</p>
  
  <p>Here's a trimmed-down version of my parent:</p>
  
  <pre><code>// "rules" is a global hash
  
  function ForumFilter() {
      this.scanText = function(title, body) {
          // Save 'this' context, as each() overwrites it
          var that = this;
          // This is jQuery each()
          $.each(rules, function(ruleName, rule) {
              // rule.search is a regex
              var match = rule.search.test(body);
              if (match)
              {
                  that.isPassed = false;
                  // ** I'd like to call a child method here,
                  // ** but it only calls the method in this class
                  that.setRuleFailed(ruleName);
              }
          });
      }
  
      this.setRuleFailed = function(ruleName) {
          this.failedRules.push(ruleName);
      }
  }
  </code></pre>
  
  <p>Here's my attempt at the child:</p>
  
  <pre><code>ForumFilterTest.prototype = new ForumFilter();
  ForumFilterTest.prototype.setRuleFailed = function(ruleName) {
      // Call parent
      ForumFilter.setRuleFailed(ruleName);
      // Record that this one has triggered
      this.triggered.push(ruleName);
  }
  </code></pre>
  
  <p>Here's my calling my parent method from a child instance:</p>
  
  <pre><code>var scanner = new ForumFilterTest();
  scanner.scanText("Hello", "Hello");
  </code></pre>
  
  <p>So, in <code>scanText</code> (which only exists in the parent) it may call <code>setRuleFailed</code>, which should call the version in <code>ForumFilterTest</code>, which in turn calls the class it overrides. Thus, as its name implies, I am trying to add a behaviour to the parent for testing purposes, so of course I want the parent method to be used if <code>ForumFilter</code> is instantiated on its own.</p>