Extend descendent object in javascript
<p>I've been learning more about javascript's prototypal inheritance. I know there is a somewhat fierce debate on whether to extend native objects and I'd like to side step that whole debate entirely in this question.</p>

<p>Is it possible to extend only descendent object in javascript?</p>

<p>To extend all objects I can do this:</p>

<pre><code>Object.prototype.size = function(){
      var length = 0;
      for(var i in this){
           if(this.hasOwnProperty(i)){
              length++;
           }
      }
      return this;
 }
</code></pre>

<p>But the problem is that It extends all objects.  What I'd like to do is have this:</p>

<pre><code>var MyNameSpace = function(){

};

MyNameSpace.Object.prototype.size = function(){
     var length = 0;
     for(var i in this){
         if(this.hasOwnProperty(i)){
             length++;
         }
     }
     return this;
}
</code></pre>

<p>That way I would only be extending the native objects in the scope of my global object.</p>

<p>any suggestions would be great thanks</p>

<p>Update:<br>
   In response to a few comments I'm adding more code to clarify what I'm trying to do.</p>

<p>I think i may have not phrased my question correctly, or maybe my thinking is incorrect, but what i'd like to be able to do is this:</p>

<pre>
<code>
    var my = new MyNameSpace();
    var my.name = {firstName : 'Hello', lastName : 'World'};
    var nameCount = my.name.size(); // 2
</code>
</pre>

<p>the code you provided will allow me to get the size of each MyNameSpace object I create, but not the object literals that are properties of the MyNameSpace object</p>
