Skip to content

Instantly share code, notes, and snippets.

@nthx
Created May 16, 2012 23:04
Show Gist options
  • Save nthx/2714748 to your computer and use it in GitHub Desktop.
Save nthx/2714748 to your computer and use it in GitHub Desktop.
Mixin long example
class Nothing
constructor: (@name="nothing") ->
doSomething: =>
"I cannot do anything"
class Presenter extends Mixin
presentYourself: =>
"My name is #{@name}"
doIPlay: =>
"I play with many #{@players}"
class Game extends Mixin
setup: =>
@name = 'Monopoly'
@players = []
@players.push "David"
sayHello: =>
@presentYourself()
something = new Nothing()
expect(something.name).toBe('nothing')
ObjectHelper.addRole(something, Presenter)
expect(something.presentYourself()).toBe('My name is nothing')
ObjectHelper.addRole(something, Game)
expect(something.sayHello()).toBe('My name is Monopoly')
expect(something.doIPlay()).toBe('I play with many David')
something.name = 'something'
expect(something.presentYourself()).toBe('My name is something')
something.players.push "John"
expect(something.doIPlay()).toBe('I play with many David,John')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment