Skip to content

Commit

Permalink
Merge pull request #76 from kbudde/master
Browse files Browse the repository at this point in the history
Chaining recipe is sharing the array object
  • Loading branch information
peterhellberg committed Mar 19, 2013
2 parents 304ab4f + 0836946 commit 38dc427
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions chapters/classes_and_objects/chaining.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ Return the `this` (i.e. `@`) object after every chained method.


{% highlight coffeescript %} {% highlight coffeescript %}
class CoffeeCup class CoffeeCup
properties: constructor: ->
strength: 'medium' @properties=
cream: false strength: 'medium'
sugar: false cream: false
sugar: false
strength: (newStrength) -> strength: (newStrength) ->
@properties.strength = newStrength @properties.strength = newStrength
@ @
Expand Down Expand Up @@ -57,13 +58,13 @@ addChainedAttributeAccessor = (obj, propertyAttr, attr) ->
obj obj


class TeaCup class TeaCup
properties: constructor: ->
size: 'medium' @properties=
type: 'black' size: 'medium'
sugar: false type: 'black'
cream: false sugar: false

cream: false
addChainedAttributeAccessor(TeaCup.prototype, 'properties', attr) for attr of TeaCup.prototype.properties addChainedAttributeAccessor(this, 'properties', attr) for attr of @properties


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


Expand Down

0 comments on commit 38dc427

Please sign in to comment.