Ownership of Javascript Object-Properties created via new
<p>for example, if i use prototype.js inside my app, the library extends the Objects prototype with some additional stuff, eg:</p>

<pre><code>// the code is not exactly like this but that doesnt matter
Object.prototype.inspect = function...
</code></pre>

<p>when i create some object, the object has NEVER the ownproperty "inspect", which of course is correct:</p>

<pre><code>// false
{}.hasOwnProperty('inspect');
</code></pre>

<p>if i create an Object-literal like this, properties created via this object-literal are ownproperties, which of course is correct too:</p>

<pre><code>var myObj = {
   myProp: 'myVal'
};

// this would return true here
myObj.hasOwnProperty('myProp');
</code></pre>

<p>BUT, if i create an object via the new operator, even the properties inside my Function are not recognized as ownproperty. </p>

<pre><code>function MyTest () {}

MyTest.prototype.myProp = function () {};

var myObj = new MyTest();

// this would return false here

myObj.hasOwnProperty('myProp');
</code></pre>

<p>can somebody explain why it is like that?
i want to iterate over an object, create a new object which only contains properties that are NOT part of the Objects.prototype (and therefore not created through prototype.js).</p>

<p>EDIT: im not the owner of the code that creates myObj, and i dont know which Function-Constructor creates myObj</p>

<p>EDIT2: thanks to niko, thats how i do it now:</p>

<pre><code>var key, newObj = {};
for (key in oldObj) {
  if (typeof newObj[key] == 'undefined') {
    newObj[key] = oldObj[key];
  }
}
for (key in newObj) {
  if (newObj.hasOwnProperty(key)) {
    // do some stuff here with properties that did not came from the objects.prototype
  }
}
</code></pre>
