title: Inheriting from JavaScript function in C++
body: <p>I have a following JavaScript base function:</p>
  
  <pre><code>function Animal { }  
  
  Animal.prototype.move = function () { 
    //... 
  }
  </code></pre>
  
  <p>I have also a derived JavaScript function like this:</p>
  
  <pre><code>function Dog {
    Dog.super_.call(this);
  }
  
  util.inherits(Dog, Animal);
  
  Dog.prototype.bark = function () {
    // ...
  }
  </code></pre>
  
  <p>Now I would like to create a C++ addon which is exactly the same as the derived
  <code>Dog</code> JavaScript function:</p>
  
  <pre><code>void Dog::Init(Handle&lt;Object&gt; exports, Handle&lt;Object&gt; module) {
    Isolate* isolate = Isolate::GetCurrent();
  
    Local&lt;Function&gt; require = Local&lt;Function&gt;::Cast(module-&gt;Get(
      String::NewFromUtf8(isolate, "require")));
  
    Local&lt;Value&gt; args[] = {
      String::NewFromUtf8(isolate, "./animal")
    };  
  
    Local&lt;Value&gt; animalModule = require-&gt;Call(module, 1, args);
  
    Local&lt;Function&gt; animalFunc = Local&lt;Function&gt;::Cast(animalModule);   
  
    Local&lt;FunctionTemplate&gt; tpl = FunctionTemplate::New(isolate, New);
    // tpl-&gt;Inherit(animalFunc); // &lt;-- HERE
    tpl-&gt;SetClassName(String::NewFromUtf8(isolate, "Dog"));
    tpl-&gt;InstanceTemplate()-&gt;SetInternalFieldCount(1);  
  
    NODE_SET_PROTOTYPE_METHOD(tpl, "bark", Bark);
  
    constructor.Reset(isolate, tpl-&gt;GetFunction());
    exports-&gt;Set(String::NewFromUtf8(isolate, "Dog"),
      tpl-&gt;GetFunction());    
  }
  </code></pre>
  
  <p>How can I get a <code>FunctionTemplate</code> from <code>animalFunc</code> / <code>animalModule</code> to be able to inherit from it in <code>tpl</code> function template? Or maybe I should somehow assign <em>animalFunc.prototype</em> to <em>tpl.prototype</em>?</p>