Skip to content
This repository
Browse code

Chaining recipe changed. Property array was shared between instances

  • Loading branch information...
commit 0836946e99dc65051fc9a91bf568dcc612dc5dd5 1 parent 304ab4f
kbudde authored March 18, 2013

Showing 1 changed file with 12 additions and 11 deletions. Show diff stats Hide diff stats

  1. 23  chapters/classes_and_objects/chaining.md
23  chapters/classes_and_objects/chaining.md
Source Rendered
@@ -13,10 +13,11 @@ Return the `this` (i.e. `@`) object after every chained method.
13 13
 
14 14
 {% highlight coffeescript %}
15 15
 class CoffeeCup
16  
-	properties:
17  
-		strength: 'medium'
18  
-		cream: false
19  
-		sugar: false
  16
+	constructor:  ->
  17
+		@properties=
  18
+			strength: 'medium'
  19
+			cream: false
  20
+			sugar: false
20 21
 	strength: (newStrength) ->
21 22
 		@properties.strength = newStrength
22 23
 		@
@@ -57,13 +58,13 @@ addChainedAttributeAccessor = (obj, propertyAttr, attr) ->
57 58
 			obj
58 59
 
59 60
 class TeaCup
60  
-	properties:
61  
-		size: 'medium'
62  
-		type: 'black'
63  
-		sugar: false
64  
-		cream: false
65  
-
66  
-addChainedAttributeAccessor(TeaCup.prototype, 'properties', attr) for attr of TeaCup.prototype.properties
  61
+	constructor:  ->
  62
+		@properties=
  63
+			size: 'medium'
  64
+			type: 'black'
  65
+			sugar: false
  66
+			cream: false
  67
+		addChainedAttributeAccessor(this, 'properties', attr) for attr of @properties
67 68
 
68 69
 earlgrey = new TeaCup().size('small').type('Earl Grey').sugar('false')
69 70
 

0 notes on commit 0836946

Please sign in to comment.
Something went wrong with that request. Please try again.