Posted 23 days ago. Visible to the public. Repeats.

Operators "in" and "of" are very inconsistent between CoffeeScript and JavaScript

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 be used for the same purpose in both languages.

Check if an object (or its prototype) has a property

CoffeeScript

Copy
var hasFoo = 'foo' of object

JavaScript

Copy
var hasFoo = 'foo' in object;

Iterate through all properties of an object

CoffeeScript

Copy
object = { ... } for key, value of object console.log("key %o has value %o", key, value);

JavaScript

Copy
var object = { ... }; for (var key in object) { var value = x[key]; console.log("key %o has value %o", key, value); }

Iterate through all values of an array

CoffeeScript

Copy
array = [...] for entry in array console.log("value is %o", entry.value)

JavaScript

Copy
var array = [...] for (var entry of array) { console.log("value is %o", value); })

Iterate through all values of an iterator

CoffeeScript

Copy
iterator = ... while entry = iterator.next() && !entry.done console.log("value is %o", entry.value)

JavaScript

Copy
var iterator = ...; for (var value of iterator) { console.log("value is %o", value); }

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Author of this card:

Avatar
Henning Koch
Last edit:
18 days ago
by Florian Leinsinger
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev