Skip to content

Commit 38dc427

Browse files
committed
Merge pull request #76 from kbudde/master
Chaining recipe is sharing the array object
2 parents 304ab4f + 0836946 commit 38dc427

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Diff for: chapters/classes_and_objects/chaining.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ Return the `this` (i.e. `@`) object after every chained method.
1313

1414
{% highlight coffeescript %}
1515
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
2021
strength: (newStrength) ->
2122
@properties.strength = newStrength
2223
@
@@ -57,13 +58,13 @@ addChainedAttributeAccessor = (obj, propertyAttr, attr) ->
5758
obj
5859

5960
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
6768

6869
earlgrey = new TeaCup().size('small').type('Earl Grey').sugar('false')
6970

0 commit comments

Comments
 (0)