Created
February 27, 2012 18:08
-
-
Save pnegri/1925913 to your computer and use it in GitHub Desktop.
Developing an Approach to Javascript Spaghetti - First Candidate
This file contains 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
Fs = require 'fs' | |
Path = require 'path' | |
Async = require 'async' | |
class Tasks | |
@do: ( methods ) -> | |
that_methods = methods | |
new ( | |
() -> | |
methods_array = [] | |
original_methods = that_methods | |
that = this | |
for index of original_methods | |
methods_array.push( original_methods[ index ].bind(that) ) | |
Async.waterfall( methods_array ) | |
)() | |
class TestingSomething | |
organize_basket: ( next ) -> | |
@basket = {} | |
next() | |
buy_3_apples: ( next )-> | |
@basket.apples = 0 unless @basket.apples | |
@basket.apples += 3 | |
next() | |
bake_apple_pie: ( next ) -> | |
@basket.apples = 0 unless @basket.apples | |
@basket.pies = 0 unless @basket.pies | |
if (@basket.apples > 1 ) | |
@basket.apples -= 2 | |
@basket.pies += 1 | |
else | |
console.log "No Apples for a Pie" | |
next() | |
balance: ( next ) -> | |
console.log @basket | |
next() | |
run: () -> | |
for i in [1..10] | |
Tasks.do([ | |
@organize_basket | |
@buy_3_apples | |
@bake_apple_pie | |
@buy_3_apples | |
@balance | |
]) | |
obj = new TestingSomething() | |
obj.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment