Created
January 2, 2011 22:58
-
-
Save chrisyour/762910 to your computer and use it in GitHub Desktop.
This would be a nice way to define a method in CoffeeScript...
This file contains 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
# 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