Last active
December 29, 2015 05:39
-
-
Save IAMIronmanSam/7623766 to your computer and use it in GitHub Desktop.
Coffescript Basic
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
| #Varaible Declaration | |
| MyWorld = | |
| script: 'Coffescript' | |
| #function | |
| text:(_arg) -> | |
| console.log "Hi "+ @script+" "+_arg | |
| #Function with parameter | |
| MyWorld.text('Your Awesome!') | |
| #Class | |
| class Medium | |
| constructor: (@name) -> | |
| # Prototype method | |
| download: (episode) -> | |
| console.log 'Downloading ' + episode + ' of ' + @name | |
| # Static method | |
| @play: (episode, name) -> | |
| console.log 'Playing ' + episode + ' of ' + name | |
| playOn: -> | |
| console.log 'unknown' | |
| #Inheritance | |
| class Podcast extends Medium | |
| constructor: (name, @description) -> | |
| super name | |
| listen: -> | |
| console.log 'Listening to ' + @name | |
| playOn: -> | |
| console.log 'iPod' | |
| class Screencast extends Medium | |
| constructor: (name, @description, @author) -> | |
| super name | |
| watch: -> | |
| console.log 'Watching ' + @name | |
| playOn: -> | |
| console.log 'iPad' | |
| # Traversing arrays and objects in CoffeeScript | |
| # The array and object we use for testing | |
| Traversal = | |
| arr = [one:1,two:2,three:3,four:4,five:5] | |
| array: if not null then for i in arr | |
| console.log i | |
| object:arr2 = | |
| one:"1" | |
| two:"2" | |
| three:"3" | |
| four:"4" | |
| five:"5" | |
| for own key of arr2 | |
| console.log "#{key}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment