Skip to content

Instantly share code, notes, and snippets.

@vojto
Created April 8, 2012 09:48
Show Gist options
  • Select an option

  • Save vojto/2336321 to your computer and use it in GitHub Desktop.

Select an option

Save vojto/2336321 to your computer and use it in GitHub Desktop.
JavaScript vs. CoffeeScript vs. IcedCoffeeScript
// 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);
});
});
}
// 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)
// 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