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
  • Iteration
  • Misc
  1. JavaScript

CoffeeScript to ES6 cheatsheet

PreviousCoffeeScriptNextAngular.js

Last updated 6 years ago

References:

Iteration

  • On object properties:

// coffee
for prop, value of obj

// ES6
_.each(obj, (value, key)=>{
});

// or (NOTE don't use it for array)
for (let prop in obj) {
}
  • On collection (array):

// coffee
for ele in arr
    console.log ele

// es6
for (let ele of arr) {
    console.log(ele);
}

// or
arr.forEach( (ele) => {
    console.log(ele);
    //  函数体内的this对象,就是定义时所在的对象,而不是使用时所在的对象
});

// or
arr.forEach(function(ele){
    console.log(ele);
    //  this is the function
});

Misc

  • Replace ==/!= with ===/!==

// coffee
class MyFile
    @EXT = '.myfile'

// es6
class MyFile {
  static Ext() {
    return '.myfile';
  }
}

, you might want to just turn that to a static method:

https://gist.github.com/danielgtaylor/0b60c2ed1f069f118562
https://robots.thoughtbot.com/replace-coffeescript-with-es6
There is no concept of class variable in ES6