Read more

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

Henning Koch
May 02, 2018Software engineer at makandra GmbH

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

var hasFoo = 'foo' of object

JavaScript

var hasFoo = 'foo' in object;

Iterate through all properties of an object

CoffeeScript

object = { ... }

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

JavaScript

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

array = [...]

for entry in array
  console.log("value is %o", entry.value)

JavaScript

var array = [...]

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

Iterate through all values of an iterator

CoffeeScript

iterator = ...

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

JavaScript

var iterator = ...;

for (var value of iterator) {
   console.log("value is %o", value); 
}
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot
Henning Koch
May 02, 2018Software engineer at makandra GmbH
Posted by Henning Koch to makandra dev (2018-05-02 10:38)