10x Developer
  • Introduction
  • HTML
    • HTML DOM Jquery
    • HTML: Form
    • CSS
    • CSS Layout
    • CSS Flexbox
    • CSS Grid
    • SASS/LESS
    • CSS/LESS/SASS Cookbook
    • Bootstrap
  • JavaScript
    • JavaScript
    • ES6
    • TypeScript
    • JavaScript Testing
    • JavaScript Event Loop
    • DOM
    • Web APIs
    • JSON
    • RegEx
    • Functional Programming
    • JavaScript Lib
    • CoffeeScript
    • CoffeeScript to ES6 cheatsheet
  • Angular.js
    • Angular
    • Angular Cookbook
    • Angular Mistakes I Made
    • Angular 1.x
  • React.js
    • React.js
  • Node
    • Node.js
    • CLI command line tool
    • Electron / Atom
    • NW.js (node-webkit)
  • Serverless
    • AWS Lambda
    • Google Cloud Function
    • Actions on Google / Google Assistant
  • Full Stack Development
    • HTTP
    • Meteor
    • MongoDB
    • Digital Ocean
    • UI
    • Sketch
    • Web Dev Resources
  • Lang
    • Ruby
  • Know Your Tools
    • Chrome DevTools
    • Editor: VS Code
    • Editor: Vim
    • Editor: Sublime
    • Editor: Atom
    • Windows
    • Git
    • Linux / Bash
    • Mac
  • Cheatsheets
Powered by GitBook
On this page
  • iterate
  • fat arrow in coffeescript
  • String with format
  • Instance method, variables
  • How to write function as a part of parameter
  • reverse for loop
  1. JavaScript

CoffeeScript

PreviousJavaScript LibNextCoffeeScript to ES6 cheatsheet

Last updated 6 years ago

more coffeescript tricks:

iterate

  • loop array: for item in arr or for item, index in arr

  • loop object: for prop, value of obj or for own property, value of object (use hasOwnProperty())

fat arrow in coffeescript

  • read

  • use => when we need @ to be the object in which method is written; use-> when we need @ to be the object in which method is executed.

String with format

print = """
  1st line
  2nd line
  #{supports interpolation}
  last line
  """

Instance method, variables

class Songs
  _titles: 0    # instance var, Although it's directly accessible, the leading _ defines it by convention as private property.
  get_count: ->
    @_titles # access instance var
  call_another_method: ->
    return @get_count() # call another instance method

How to write function as a part of parameter

Router.go 'home', -> 
  this.render 'home'
, 
  name: 'h'
  old: 'b'

reverse for loop

coffeescript reverse for loop: for i in [arr.length-1..0] by -1

https://gist.github.com/dfurber/993584
this
iterations in coffeescript