title: Privileged methods vs public methods, memory and performance considerations
body: <p>I'm rewriting a web app, currently the whole API is designed in a such a way in which all object's function members are privileged methods. If I'm not misunderstanding the concepts, privileged methods waste memory since there's a copy of each one of them for each object's instance, while public methods save memory since there is only one copy for all instances. No problem until this point.</p>
  
  <p>However, most of the objects on my app are (dynamically created) DOM objects. Currently it looks more or less like this:</p>
  
  <pre><code>function DOMObj(parent,tag,x,y,w,h,...){
     var obj = document.createElement(tag);
     .
     .
     .
     parent.appendChild(obj);
     obj.Method1 = function(){/* some code */}
     obj.Method2 = function(){/* some code */}
     .
     .
     .
     obj.MethodN = function(){/* some code */}
     return obj;
  }
  .
  .
  .
  txt = DOMObj(document.body,"div",...); 
  txt.innerHTML = "some text";
  </code></pre>
  
  <p>Since the DOM itself takes care of creating the object, I don't have to use the <strong>new</strong> operator, however if I make the methods public I would have to rewrite it like this:</p>
  
  <pre><code>function DOMObj(parent,tag,x,y,w,h,...){
     var obj = document.createElement(tag);
     .
     .
     .
     parent.appendChild(obj);
     this.DOMObj = obj;
  }
  DOMObj.prototype = {
     Method1: function(){/* some code */},
     Method2: function(){/* some code */},
     .
     .
     .
     MethodN: function(){/* some code */}
  }
  .
  .
  .
  txt = new DOMObj(document.body,"div",...); 
  txt.DOMObj.innerHTML = "some text";
  </code></pre>
  
  <p>In this case every time I create a new object I'm forced to use the <strong>new</strong> operator which obviously has an impact on memory consumption, but how strong? and most importantly, compared with the amount of memory I'd be saving, the balance would be positive or negative? </p>
  
  <p>I also will be adding a small overhead (imperceptible if you will), I read someone's blog how said that public methods had a positive impact on performance when compared to privileged methods but he didn't explain the supposed reason neither showed any numbers to support his claim, so, is this claim true? and if it is, this gain will be nullified by the overhead I'll be adding? or will I still be gaining? and if so, will it be notorious at least on the slowest smart phone?</p>
  
  <p>Obviously the answer to this questions depend on the number of created objects, the number of methods and the internals of the Javascript engine, so I'm about to (almost) blindly invest a lot of effort in something that can either have a negligible or tremendous impact, which doesn't seem very smart and which also leads me to the core question: "how big is big?". Or in other words, <strong>how can I accurately calculate the impact a change like this will have on the performance of my app?</strong>, is there the required information to perform such calculation available somewhere in the first place?. At least I need to know (based on some reliable numbers) if a change like this is worth the effort.</p>
  
  <p>Can anyone with experience in the internals of V8 or any other JavaScript engine shed some light on this?.</p>