Skip to content

Commit 2e1ac8c

Browse files
committed
Automatic merge from master.
1 parent 36bb740 commit 2e1ac8c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,22 @@ <h1>JavaScript Garden</h1>
269269
way to exclude properties that are not defined on the object <strong>itself</strong>, but
270270
somewhere on its prototype chain.<br />
271271
</p>
272+
</section><section><header><h3><code>hasOwnProperty</code> as a property</h3></header>
273+
<p>JavaScript does not protect the property name <code>hasOwnProperty</code>; therefore, if the
274+
possibility exists that an object might have a property with this name, it is
275+
necessary to use an <em>external</em> <code>hasOwnProperty</code> in order to get correct results.</p>
276+
<pre><code>var foo = {
277+
hasOwnProperty: function() {
278+
return false;
279+
},
280+
bar: 'Here be dragons'
281+
};
282+
283+
foo.hasOwnProperty('bar'); // always returns false
284+
285+
// Use another hasOwnProperty and call it with 'this' set to foo
286+
{}.hasOwnProperty.call(foo, 'bar'); // true
287+
</code></pre>
272288
</section><section><header><h3>In conclusion</h3></header>
273289
<p>When checking for the existence of a property on a object, <code>hasOwnProperty</code> is
274290
the <strong>only</strong> method of doing so. It is also recommended to make <code>hasOwnProperty</code>

0 commit comments

Comments
 (0)