Skip to content

Instantly share code, notes, and snippets.

@slloyd
Created May 3, 2013 22:33
Show Gist options
  • Save slloyd/5514779 to your computer and use it in GitHub Desktop.
Save slloyd/5514779 to your computer and use it in GitHub Desktop.
DERP.coffee
foo =
  a: 1
  b: 2
  c: 3

x = Object.keys foo

y = key for key, value of foo

z = (key for key, value of foo)

console.log('x: ', x)
console.log('y: ', y)
console.log('z: ', z)

console:

x:  ["a", "b", "c"]
y:  c
z:  ["a", "b", "c"]

The compiled JS:

var foo, key, value, x, y, z;

foo = {
  a: 1,
  b: 2,
  c: 3
};

x = Object.keys(foo);

for (key in foo) {
  value = foo[key];
  y = key;
}

z = (function() {
  var _results;

  _results = [];
  for (key in foo) {
    value = foo[key];
    _results.push(key);
  }
  return _results;
})();

console.log('x: ', x);

console.log('y: ', y);

console.log('z: ', z);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment