title: Javascript constructor, prototype and instantiation. Architecture and Framework
body: <p>I'm developing a "framework" and find myself at writing modules.</p>
  
  <p>for each module exists a set of common initialization rules and common set of functions.</p>
  
  <p>STEP 1. constructor function:</p>
  
  <pre><code>var ns = "namespace1";
  t.scenarios[ns] = function (container, instanceName, options) {
      // common for all scenarios, e.g. options initialization
      t.core.defaultScenarioConstructor(this, ns, container, instanceName, options)
  
      // things only for NAMESPACE1
      this.PROPERTY1 = 1;
  }
  </code></pre>
  
  <p><strong>STEP 2.</strong> (question related)
  then I have a prototype</p>
  
  <pre><code>var p = t.scenarios[ns].prototype;
  
  p.newfunction = function(){
      this.PROPERTY1; // accessible
  } 
  </code></pre>
  
  <p>which gets filled with THINGS_ONLY_FOR_NAMESPACE1</p>
  
  <pre><code>t.core.defaultScenarioPrototype(p);
  </code></pre>
  
  <p>STEP 3 / 4.
  instantiate class (with new keyword) &amp; call dom builder</p>
  
  <pre><code>p.initNewView = function(container) {/* build dom and assign handlers*/}
  </code></pre>
  
  <p><br></p>
  
  <p>Now the question... I would like to do common constructor/prototype initialization within the other "core" module. If on STEP 2 we add functions to prototype then they have "this" keyword and can access CURRENT_INTANCE fields, e.g. PROPERTY1.</p>
  
  <p>If however the prototype is passed as a variable to "defaultScenarioPrototype" builder, then all functions have the other "this" of CORE class, where lives the builder.
  <br>
  How should we add "common" functions to a prototype from another module?</p>