Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Passing the wrong object to hasOwnProperty method.

  • Loading branch information...
commit 1546101896aab6a09303fcecbdf18d72726e6b58 1 parent a2d2b63
@brunocoelho brunocoelho authored
Showing with 9 additions and 9 deletions.
  1. +9 −9 doc/en/object/hasownproperty.md
View
18 doc/en/object/hasownproperty.md
@@ -5,26 +5,26 @@ on its [prototype chain](#object.prototype), it is necessary to use the
`hasOwnProperty` method which all objects inherit from `Object.prototype`.
> **Note:** It is **not** enough to check whether a property is `undefined`. The
-> property might very well exist, but its value just happens to be set to
+> property might very well exist, but its value just happens to be set to
> `undefined`.
-`hasOwnProperty` is the only thing in JavaScript which deals with properties and
+`hasOwnProperty` is the only thing in JavaScript which deals with properties and
does **not** traverse the prototype chain.
// Poisoning Object.prototype
- Object.prototype.bar = 1;
+ Object.prototype.bar = 1;
var foo = {goo: undefined};
-
+
foo.bar; // 1
'bar' in foo; // true
foo.hasOwnProperty('bar'); // false
foo.hasOwnProperty('goo'); // true
-Only `hasOwnProperty` will give the correct and expected result; this is
-essential when iterating over the properties of any object. There is **no** other
-way to exclude properties that are not defined on the object itself, but
-somewhere on its prototype chain.
+Only `hasOwnProperty` will give the correct and expected result; this is
+essential when iterating over the properties of any object. There is **no** other
+way to exclude properties that are not defined on the object itself, but
+somewhere on its prototype chain.
### `hasOwnProperty` as a Property
@@ -45,7 +45,7 @@ necessary to use an *external* `hasOwnProperty` to get correct results.
({}).hasOwnProperty.call(foo, 'bar'); // true
// It's also possible to use the hasOwnProperty property from the Object property for this purpose
- Object.prototype.hasOwnProperty.call(obj, 'bar'); // true
+ Object.prototype.hasOwnProperty.call(foo, 'bar'); // true
### In Conclusion
Please sign in to comment.
Something went wrong with that request. Please try again.