Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Chaining recipe changed. Property array was shared between instances

  • Loading branch information...
commit 0836946e99dc65051fc9a91bf568dcc612dc5dd5 1 parent 304ab4f
@kbudde kbudde authored
Showing with 12 additions and 11 deletions.
  1. +12 −11 chapters/classes_and_objects/chaining.md
View
23 chapters/classes_and_objects/chaining.md
@@ -13,10 +13,11 @@ Return the `this` (i.e. `@`) object after every chained method.
{% highlight coffeescript %}
class CoffeeCup
- properties:
- strength: 'medium'
- cream: false
- sugar: false
+ constructor: ->
+ @properties=
+ strength: 'medium'
+ cream: false
+ sugar: false
strength: (newStrength) ->
@properties.strength = newStrength
@
@@ -57,13 +58,13 @@ addChainedAttributeAccessor = (obj, propertyAttr, attr) ->
obj
class TeaCup
- properties:
- size: 'medium'
- type: 'black'
- sugar: false
- cream: false
-
-addChainedAttributeAccessor(TeaCup.prototype, 'properties', attr) for attr of TeaCup.prototype.properties
+ constructor: ->
+ @properties=
+ size: 'medium'
+ type: 'black'
+ sugar: false
+ cream: false
+ addChainedAttributeAccessor(this, 'properties', attr) for attr of @properties
earlgrey = new TeaCup().size('small').type('Earl Grey').sugar('false')
Please sign in to comment.
Something went wrong with that request. Please try again.