It is quite easy to migrate from CoffeeScript to ES6. You can use decaffeinate to convert your CoffeeScript source to modern JavaScript. Install decaffeinate globally: npm install -g decaffeinate

CoffeeScript and JavaScript (ECMAScript) both have operators in and of. Each language use them for more than one purpose. There is not a single case where the same operator can...

...purpose in both languages. Check if an object (or its prototype) has a property CoffeeScript var hasFoo = 'foo' of object JavaScript var hasFoo = 'foo' in object; Iterate through all properties...

...migrate a Rails application from Sprockets to Webpack(er), you can either transpile your CoffeeScript files to JavaScript or integrate a CoffeeScript compiler to your new process. This checklist can...

...be used to achieve the latter. If you need to continue exposing your CoffeeScript classes to the global namespace, define them on window directly: -class @User +class window.User Replace Sprocket...

makandra dev

...an outside scope: (function() { var foo = "value"; // foo is scoped to this IIFE })(); In Coffeescript an IIFE looks like this: (-> foo = "value" # foo is scoped to this IIFE )()

...scoped to this IIFE This makes do the best way to emulate let in Coffeescript. Example: When you need IIFEs You would expect the following code to open three dialogs...

coffeescript.org contains only documentation for the latest CoffeeScript version. Version 2 transpiles to ES6. We stopped using CoffeeScript a while ago, but older projects still use version 1 which transpiles...

...older projects may be somewhat hard. Here are some links to version 1 documentation: http://coffeescript.org/v1/ Fully functional If this ever goes away, here are some alternatives:

...extensions, like .rb, .erb, .css, .js. When using different markup like Haml, Sass, or CoffeeScript, you need to make Rails aware of its extensions and how comments work in each...

Coffeescript allows you to create classes whose methods are automatically bound to the correct this. You can do this by using a fat arrow: class Person constructor: (name) -> @name = name...

...t think there is a workaround for this, you simply cannot clone instances of Coffeescript instances as you would clone other Javascript hashes. If you need cloning, you would probably...

...var value of iterator) { console.log(value); } While there is a for...of construct in Coffeescript, it iterates through property/value pairs and cannot be used to access iterable objects.

...through an iterator in Coffeescript you need to do something like this: iterator = ...; while (entry = iterator.next()) && !entry.done console.log(entry.value) The parentheses in the while cannot be omitted...

gist.github.com

The NestedHash class allows you to read and write hashes of any depth. Examples: hash = {} NestedHash.write hash, 'a', 'b', 'c...

This may be hard to find in the docs, but if you want CoffeeScript classes that instantiate their properties from a hash of attributes (like ActiveRecord), do it like this...

constructor: ({ @name, @email }) -> # empty contstructor is fine, CoffeeScript will do the magic. Example: var batman = new User(name: 'Bruce Wayne', email: 'batman@example.com') batman.name # => 'Bruce Wayne...

Today in computer: In Coffeescript, on and yes are aliases for true. off and no are aliases for false. Defining variables or functions with such a name will give you...

How to define and call class methods in CoffeeScript classes: class Foo @classMethod: -> @otherClassMethod() instanceMethod: -> @otherInstanceMethod() @constructor.classMethod...

coffeescript.org

...Hash#has_key? does in Ruby: Return whether an object has a property. However, Coffeescript has its own in operator that checks for array inclusion. To check whether an object...

...has a property, use of: Javascript 'name' in {name: 'Horst'} # => true Coffeescript # wrong 'name' in {name: 'Horst'} # => false # correct 'name' of {name: 'Horst'} # => true 1 in [1,2,3] # => true...

makandra dev
jashkenas.github.com

Imagine all the syntactical delights of Ruby and Haml for your JavaScript. You write in a nice language, but get...

github.com

We will use this for new Angular code. Consider the guide in "beta". Things will still refine, but the general...

...unfortunately clutters your code with awkward calls to the _ helper. Fortunately when you use CoffeeScript you don't need any of that. CoffeeScript has a very versatile for keyword that...

...if your default value is expensive to construct): x = _.defaultTo(x, 'default-value') With CoffeeScript CoffeeScript lets you write: x ?= 'default-value...

...now.toString()) interval = setInterval(updateTime, 1000) scope.$on '$destroy', -> clearInterval(interval) Create re-arming timers (Coffeescript) A re-arming timer is a timeout that, when triggered, schedules itself again and again...

...Because $timeout returns a promise for the timer's execution, and because Coffeescript uses the last expression in a block as implicit return value, this pattern is a great way...

...this.firstName = parts[0]; this.lastName = parts[1]; } }); Browser compatibility Works with IE9+ and real browsers. CoffeeScript CoffeeScript doesn't support getter/setter functions, and probably never will. However, you can define getters/setters...

...this into vanilla JavaScript using promises or generators. async/await is available in Babel and CoffeeScript 2 (which needs Babel). Writing functions with async function throwOnMonday() { if (new Date().getDay...

console.log(...array) EcmaScript 5 (ES5) var array = [1, 2, 3] console.log.apply(console, array) CoffeeScript console.log(array...

...first. Among other ways, you can do so with a custom filter. # Filter in Coffeescript...: @app.filter 'htmlSafe', ['$sce', ($sce) -> $sce.trustAsHtml ] # ...or JS: app.filter('htmlSafe', [ '$sce', function($sce) { return $sce.trustAsHtml; } ]);

In order to send those headers for specific hosts, add this piece of CoffeeScript directly after jQuery (but before jquery-ujs): whitelisted = (url) -> for domain in ["http://trusted.host...

But you can use your directive's link function. Here's some CoffeeScript for you: @app.directive 'myStuff', [-> restrict: 'E' transclude: true template: """ default goes here """ link: (scope, element...