Last active
September 28, 2017 16:08
-
-
Save robinduckett/6b05a21a0a36a45ab4ab to your computer and use it in GitHub Desktop.
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
// Callback Hell. You and I both know it's hell. | |
// Here's a secret: Escape Callback Hell... | |
// ... by using classes, you fucking jackass. | |
// This is shit: | |
fs.readdir('tmp', function(err, list) { | |
async.map(list, function(item, cb) { | |
cb(null, item.toUpperCase()); | |
}, function(err, results) { | |
console.log(results); | |
}); | |
}); | |
// This is how it has always supposed to be done | |
function LoudFiles() { | |
fs.readdir('tmp', this.dir.bind(this)); | |
} | |
LoudFiles.prototype.dir = function(err, list) { | |
if (err) { | |
return console.error(err); | |
} | |
async.map(list, this.embiggen.bind(this), this.results.bind(this)); | |
}; | |
LoudFiles.prototype.embiggen = function(item, callback) { | |
callback(null, item.toUpperCase()); | |
}; | |
LoudFiles.prototype.results = function(err, results) { | |
console.log(results); | |
}; | |
var loud = new LoudFiles(); | |
// Now, don't let me see you fuck around anymore. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment