Skip to content
This repository

Passing wrong object to hasOwnProperty method. #159

Merged
merged 2 commits into from about 1 year ago

2 participants

Bruno Coelho Ivo Wetzel
Bruno Coelho

The correct object is 'foo' but it was 'obj' instead.

Ivo Wetzel BonsaiDen merged commit 2e258af into from March 28, 2013
Ivo Wetzel BonsaiDen closed this March 28, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Jan 24, 2013
Bruno Coelho Passing the wrong object to hasOwnProperty method. 1546101
Jan 25, 2013
Bruno Coelho Cosmetic. 4a94b22
This page is out of date. Refresh to see the latest.
18  doc/en/object/hasownproperty.md
Source Rendered
@@ -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
38  doc/en/object/prototype.md
Source Rendered
... ...
@@ -1,23 +1,23 @@
1 1
 ## The Prototype
2 2
 
3  
-JavaScript does not feature a classical inheritance model; instead, it uses a 
4  
-*prototypal* one. 
  3
+JavaScript does not feature a classical inheritance model; instead, it uses a
  4
+*prototypal* one.
5 5
 
6  
-While this is often considered to be one of JavaScript's weaknesses, the 
  6
+While this is often considered to be one of JavaScript's weaknesses, the
7 7
 prototypal inheritance model is in fact more powerful than the classic model.
8 8
 It is, for example, fairly trivial to build a classic model on top of a
9 9
 prototypal model, while the other way around is a far more difficult task.
10 10
 
11 11
 JavaScript is the only widely used language that features prototypal
12 12
 inheritance, so it can take time to adjust to the differences between the two
13  
-models. 
  13
+models.
14 14
 
15 15
 The first major difference is that inheritance in JavaScript uses *prototype
16 16
 chains*.
17 17
 
18 18
 > **Note:** Simply using `Bar.prototype = Foo.prototype` will result in both objects
19  
-> sharing the **same** prototype. Therefore, changes to either object's prototype 
20  
-> will affect the prototype of the other as well, which in most cases is not the 
  19
+> sharing the **same** prototype. Therefore, changes to either object's prototype
  20
+> will affect the prototype of the other as well, which in most cases is not the
21 21
 > desired effect.
22 22
 
23 23
     function Foo() {
@@ -36,11 +36,11 @@ chains*.
36 36
     // Make sure to list Bar as the actual constructor
37 37
     Bar.prototype.constructor = Bar;
38 38
 
39  
-    var test = new Bar() // create a new bar instance
  39
+    var test = new Bar(); // create a new bar instance
40 40
 
41 41
     // The resulting prototype chain
42 42
     test [instance of Bar]
43  
-        Bar.prototype [instance of Foo] 
  43
+        Bar.prototype [instance of Foo]
44 44
             { foo: 'Hello World' }
45 45
             Foo.prototype
46 46
                 { method: ... }
@@ -48,14 +48,14 @@ chains*.
48 48
                     { toString: ... /* etc. */ }
49 49
 
50 50
 In the code above, the object `test` will inherit from both `Bar.prototype` and
51  
-`Foo.prototype`; hence, it will have access to the function `method` that was 
  51
+`Foo.prototype`; hence, it will have access to the function `method` that was
52 52
 defined on `Foo`. It will also have access to the property `value` of the
53 53
 **one** `Foo` instance that is its prototype. It is important to note that `new
54  
-Bar()` does **not** create a new `Foo` instance, but reuses the one assigned to 
  54
+Bar()` does **not** create a new `Foo` instance, but reuses the one assigned to
55 55
 its prototype; thus, all `Bar` instances will share the **same** `value` property.
56 56
 
57  
-> **Note:** Do **not** use `Bar.prototype = Foo`, since it will not point to 
58  
-> the prototype of `Foo` but rather to the function object `Foo`. So the 
  57
+> **Note:** Do **not** use `Bar.prototype = Foo`, since it will not point to
  58
+> the prototype of `Foo` but rather to the function object `Foo`. So the
59 59
 > prototype chain will go over `Function.prototype` and not `Foo.prototype`;
60 60
 > therefore, `method` will not be on the prototype chain.
61 61
 
@@ -71,7 +71,7 @@ hasn't found the specified property, it will return the value
71 71
 ### The Prototype Property
72 72
 
73 73
 While the prototype property is used by the language to build the prototype
74  
-chains, it is still possible to assign **any** given value to it. However, 
  74
+chains, it is still possible to assign **any** given value to it. However,
75 75
 primitives will simply get ignored when assigned as a prototype.
76 76
 
77 77
     function Foo() {}
@@ -85,9 +85,9 @@ creation of prototype chains.
85 85
 The lookup time for properties that are high up on the prototype chain can have
86 86
 a negative impact on performance, and this may be significant in code where
87 87
 performance is critical. Additionally, trying to access non-existent properties
88  
-will always traverse the full prototype chain. 
  88
+will always traverse the full prototype chain.
89 89
 
90  
-Also, when [iterating](#object.forinloop) over the properties of an object 
  90
+Also, when [iterating](#object.forinloop) over the properties of an object
91 91
 **every** property that is on the prototype chain will be enumerated.
92 92
 
93 93
 ### Extension of Native Prototypes
@@ -95,12 +95,12 @@ Also, when [iterating](#object.forinloop) over the properties of an object
95 95
 One mis-feature that is often used is to extend `Object.prototype` or one of the
96 96
 other built in prototypes.
97 97
 
98  
-This technique is called [monkey patching][1] and breaks *encapsulation*. While 
99  
-used by popular frameworks such as [Prototype][2], there is still no good 
  98
+This technique is called [monkey patching][1] and breaks *encapsulation*. While
  99
+used by popular frameworks such as [Prototype][2], there is still no good
100 100
 reason for cluttering built-in types with additional *non-standard* functionality.
101 101
 
102  
-The **only** good reason for extending a built-in prototype is to backport 
103  
-the features of newer JavaScript engines; for example, 
  102
+The **only** good reason for extending a built-in prototype is to backport
  103
+the features of newer JavaScript engines; for example,
104 104
 [`Array.forEach`][3].
105 105
 
106 106
 ### In Conclusion
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.