Created
April 8, 2012 09:48
-
-
Save vojto/2336321 to your computer and use it in GitHub Desktop.
JavaScript vs. CoffeeScript vs. IcedCoffeeScript
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
| // JavaScript | |
| auth: function(username, password, callback) { | |
| var self = this; | |
| var hash = this._encodePassword(password); | |
| this.model.find({name: username, encoded_password: hash}, function(err, docs) { | |
| if (docs.length == 0) return callback(false); | |
| var user = docs[0]; | |
| self._generateToken(user, function(token) { | |
| callback(user, token); | |
| }); | |
| }); | |
| } |
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
| // CoffeeScript | |
| auth: (username, password, callback) -> | |
| hash = @_encodePassword(password) | |
| @model.find {name: username, encoded_password: hash}, (err, docs) => | |
| return callback(false) if docs.length == 0 | |
| user = docs[0] | |
| @_generateToken user, (token) -> | |
| callback(user, token) |
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
| // IcedCoffeeScript | |
| auth: (username, password, callback) -> | |
| hash = @_encodePassword(password) | |
| await @model.find {name: username, encoded_password: hash}, defer err, docs | |
| return callback(false) if docs.length == 0 | |
| user = docs[0] | |
| await @_generateToken user, defer token | |
| callback(user, token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment