title: Javascript Privilege Function Inheritance
body: <p>I have spent the past few weeks doing a ton of research on Javascript inheritance. Firstly, I want to say that I am NOT trying to implement class-based inheritance in Javascript, however, I am trying to mimic inheritance CORRECTLY using Javascript's prototypal nature. This may be beating a dead horse, but here goes my question:</p>
  
  <p>I have two simple functions:</p>
  
  <pre><code>function Animal(arg) {
      var a = arg;
  
      //privileged function has access to private variable
      this.sayHi = function(name) {
          // can access a here if needed
          console.log('Hi: ' + name);
      }
  }
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>function Person(arg) {
      this.sayHi = function(name) {
          super.sayHi(name + '!!!');
      };
  }
  
  Person.inheritsFrom(Animal);
  </code></pre>
  
  <p>The following would be the expected result:</p>
  
  <pre><code>var animal = new Animal('cow');
  animal.sayHi('John'); // Hi: John
  
  var person = new Person('adult');
  person.sayHi('Fred'); // Hi: Fred!!!
  </code></pre>
  
  <p>The "inheritsFrom()" method that I'm using for inheritance looks like:</p>
  
  <pre><code>Function.prototype.inheritsFrom = function(parent) {
      if(parent.constructor == Function) { //Normal Inheritance
          this.prototype = new parent;
          this.prototype.constructor = this;
          this.prototype.parent = parent.prototype;
      } else  { //Pure Virtual Inheritance
          this.prototype = parent;
          this.prototype.constructor = this;
          this.prototype.parent = parent;
      }
      return this;
  }
  </code></pre>
  
  <p>These are some of my references:
  <a href="http://phrogz.net/JS/classes/OOPinJS2.html" rel="nofollow">http://phrogz.net/JS/classes/OOPinJS2.html</a>
  <a href="http://www.crockford.com/javascript/inheritance.html" rel="nofollow">http://www.crockford.com/javascript/inheritance.html</a>
  <a href="https://medium.com/javascript-scene/common-misconceptions-about-inheritance-in-javascript-d5d9bab29b0a" rel="nofollow">https://medium.com/javascript-scene/common-misconceptions-about-inheritance-in-javascript-d5d9bab29b0a</a></p>
  
  <p>Lots of good info, still can't figure out how to inherit "privileged" methods as shown above. I'm able to call the privileged method of the parent class. Please see the following JS Fiddle: <a href="https://jsfiddle.net/jxjk5hm9/" rel="nofollow">https://jsfiddle.net/jxjk5hm9/</a></p>
  
  <p>Any guidance on inheriting privileged methods is greatly appreciated, thanks!</p>