Skip to content

Instantly share code, notes, and snippets.

@chrisyour
Created January 2, 2011 22:58
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 chrisyour/762910 to your computer and use it in GitHub Desktop.
Save chrisyour/762910 to your computer and use it in GitHub Desktop.
This would be a nice way to define a method in CoffeeScript...
# The current way to define and run a method in CoffeeScript:
hello = (name) ->
alert 'Hello ' + name
hello 'Chris'
# JavaScript output:
var hello;
hello = function(name) {
return alert('Hello ' + name);
};
hello('Chris');
# ---
# Wouldn't it be great to define a CoffeeScript method using Ruby syntax like this:
def hello(name)
alert "Hello #{name}"
end
hello 'Chris'
# JavaScript output would be the same:
var hello;
hello = function(name) {
return alert('Hello ' + name);
};
hello('Chris');
# If we used keywords like def, end, and perhaps also the proc syntax to define CoffeeScript methods
# we wouldn't need the whitespace and the overall syntax would be more like Ruby.
# Of course, this is just my initial opinion after a quick browse through the language.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment