Created
June 20, 2012 17:35
-
-
Save taiansu/2961086 to your computer and use it in GitHub Desktop.
More about JavaScript & CoffeeScript arguments
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
motorcycle = ({ brand, year } = { brand: 'Unknown', year: "1999" }) -> | |
alert "brand: #{brand}, year: #{year}" | |
motorcycle() | |
#brand: 'Unknown', year: "1999" | |
motorcycle year:"2005", brand:"YAMAHA" | |
#brand: 'YAMAHA', year: 2005 |
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
#Section I | |
run_from_killer = (survivors..., victim)-> | |
console.log "dead: #{victim}, survive: #{survivors}" | |
run_from_killer "John" | |
#dead: John, survive: | |
run_from_killer "John","Bob","Alex","Sam" | |
#dead: Sam, survive: John,Bob,Alex | |
#Section II | |
fruit = (first, middle..., last) -> | |
console.log "first: #{first}, last: #{last}, middle: #{middle}" | |
fruit "apple", "banana" | |
#first: apple, last: banana, middle: | |
fruit "apple", "banana", "coconut", "dragon fruit" | |
#first: apple, last: dragon fruit, middle: banana,coconut | |
#Section III | |
my_cargo = ["cherry","pear","papaya","orange","mango"] | |
fruit my_cargo... | |
#first: cherry, last: mango, middle: pear,papaya,orange | |
#first: apple, last: dragon fruit, middle: banana,coconut |
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
function showName(name){ | |
console.log(name.first + " " + name["last"] + " "+ name["middle"]); | |
} | |
showName({"last" : "Lee", | |
"first" : "John"}) | |
//John Lee undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment