Created
May 16, 2012 23:04
-
-
Save nthx/2714748 to your computer and use it in GitHub Desktop.
Mixin long example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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