Skip to content

Instantly share code, notes, and snippets.

@jomontanari
Created April 23, 2012 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jomontanari/2468392 to your computer and use it in GitHub Desktop.
Save jomontanari/2468392 to your computer and use it in GitHub Desktop.
Code snippets for ThoughtWorks Team Hug presentation - comparing JavaScript and CoffeeScript (part 2)
var textColor;
if (result === "failed") {
textColor = "red";
} else if (result === "not run") {
textColor = "yellow";
} else {
textColor = "green";
}
textColor =
if result is "failed"
"red"
else if result is "not run"
"yellow"
else
"green"
var teamHugPresentationList = [ "CoffeeScript", "Whiskey", "Consulting"];
var whoopsie = function() {
teamHugPresentationList = [];
return teamHugPresentationList;
}
teamHugPresentationList = [ "CoffeeScript", "Whiskey", "Consulting"]
whoopsie ->
teamHugPresentationList = []
teamHugPresentationList
var TeamHugPresentation = function(title, presenter) {
return {
getHeadline: function() {
return title + " by " + presenter;
}
}
};
var myPresentation = TeamHugPresentation("CoffeeScript", "Jo Cranford");
var TeamHugPresentation = function(title, presenter) {
this.getHeadline = function() {
return title + " by " + presenter;
};
};
var myPresentation = new TeamHugPresentation("CoffeeScript", "Jo Cranford");
var TeamHugPresentation = function(title, presenter) {
this.title = title;
this.presenter = presenter;
};
TeamHugPresentation.prototype.getHeadline = function() {
return this.title + " by " + this.presenter;
};
var myPresentation = new TeamHugPresentation("CoffeeScript", "Jo Cranford");
class TeamHugPresentation
constructor: (@title, @presenter) ->
getHeadline: ->
@title + " " + @presenter
weatherInCities =
(("#{city.name}: #{city.weather}") for city in listOfCities)
var i, weatherInCities;
weatherInCities = [];
for(i = 0; i < listOfCities.length; i++) {
var city = listOfCities[i];
weatherInCities.push(city.name + ":" + city.weather);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment