class Person constructor: (@name) -> say_hello: -> console.log "Hello, my name's #{@name}" new Person('Ben').say_hello()
class Person { constructor(name) { this.name = name; } say_hello() { console.log(`Hello, my name's ${this.name}'`); } } new Person('Ben').say_hello()
square = (x) -> x * x
square = (x) => x * x;
fill = (container, liquid = "coffee") -> "Filling the #{container} with #{liquid}..."
fill = (container, liquid = "coffee") => { return `Filling the ${container} with ${liquid}`; };
helpers = version: "1.0.0" log: () -> console.log "Logging..."
helpers = { version: "1.0.0", log() { console.log("Logging...") } }
class Tab constructor: -> $('.el').on 'click', @clicked clicked: => conosle.log 'clicked'
class Tab { constructor() { $('.el').on('click', () => this.clicked); } clicked() { console.log('clicked'); } }
theBait = 1000 theSwitch = 0 [theBait, theSwitch] = [theSwitch, theBait]
var theBait = 1000 var theSwitch = 0 var [theBait, theSwitch] = [theSwitch, theBait]
weatherReport = (location) -> [location, 72, "Mostly Sunny"] [city, temp, forecast] = weatherReport "Berkeley, CA"
var weatherReport = (location) => { return [location, 72, "Mostly sunny"]; } var [city, temp, forecast] = weatherReport("Bristol, UK");
class Person constructor: (options) -> {@name, @age, @height = 'average'} = options tim = new Person name: 'Tim', age: 4
class Person { constructor(options) { [this.name, this.age, this.height = 'average'] = options; } } tim = new Person({name: 'Tim', age: 4});
By Benjamin Reid