@@ -5,26 +5,26 @@ on its [prototype chain](#object.prototype), it is necessary to use the
5
5
` hasOwnProperty ` method which all objects inherit from ` Object.prototype ` .
6
6
7
7
> ** Note:** It is ** not** enough to check whether a property is ` undefined ` . The
8
- > property might very well exist, but its value just happens to be set to
8
+ > property might very well exist, but its value just happens to be set to
9
9
> ` undefined ` .
10
10
11
- ` hasOwnProperty ` is the only thing in JavaScript which deals with properties and
11
+ ` hasOwnProperty ` is the only thing in JavaScript which deals with properties and
12
12
does ** not** traverse the prototype chain.
13
13
14
14
// Poisoning Object.prototype
15
- Object.prototype.bar = 1;
15
+ Object.prototype.bar = 1;
16
16
var foo = {goo: undefined};
17
-
17
+
18
18
foo.bar; // 1
19
19
'bar' in foo; // true
20
20
21
21
foo.hasOwnProperty('bar'); // false
22
22
foo.hasOwnProperty('goo'); // true
23
23
24
- Only ` hasOwnProperty ` will give the correct and expected result; this is
25
- essential when iterating over the properties of any object. There is ** no** other
26
- way to exclude properties that are not defined on the object itself, but
27
- somewhere on its prototype chain.
24
+ Only ` hasOwnProperty ` will give the correct and expected result; this is
25
+ essential when iterating over the properties of any object. There is ** no** other
26
+ way to exclude properties that are not defined on the object itself, but
27
+ somewhere on its prototype chain.
28
28
29
29
### ` hasOwnProperty ` as a Property
30
30
@@ -45,7 +45,7 @@ necessary to use an *external* `hasOwnProperty` to get correct results.
45
45
({}).hasOwnProperty.call(foo, 'bar'); // true
46
46
47
47
// It's also possible to use the hasOwnProperty property from the Object property for this purpose
48
- Object.prototype.hasOwnProperty.call(obj , 'bar'); // true
48
+ Object.prototype.hasOwnProperty.call(foo , 'bar'); // true
49
49
50
50
51
51
### In Conclusion
0 commit comments