Created
October 16, 2013 11:01
-
-
Save misterdai/7006043 to your computer and use it in GitHub Desktop.
Considering approaches of laying out code and handling callbacks. Which one would you pick? getData1, getData2 or getData3?... Or some other method?
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
request = require 'request' | |
class Test | |
_processData: (details, callback, error, response, body) => | |
if error? | |
return callback error | |
if reponse.statusCode isnt 200 | |
return callback(new Error(response.statusCode)) | |
try | |
callback null, {data: JSON.parse(body), details: details} | |
catch error | |
callback error | |
getData1: (details, callback) => | |
request details.url, @_processData.bind(@, details, callback) | |
# ----- OR ------ | |
getData2: (details, callback) => | |
request details.url, (error, response, body) => | |
@_processData(details, callback, error, response, body) | |
# ----- OR ----- | |
getData3: (details, callback) => | |
request details.url, (error, response, body) => | |
if error? | |
return callback error | |
if reponse.statusCode isnt 200 | |
return callback(new Error(response.statusCode)) | |
try | |
callback null, {data: JSON.parse(body), details: details} | |
catch error | |
callback error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment