1

In JS, I can do something like this:

for(i in MyClass.prototype) {
  console.log(i);
}

And it will show me the method names. That's fine.

Now, if I do this with coffeescript:

for i in MyClass.prototype
  console.log i

It will be compiled to:

var i, _i, _len, _ref;

_ref = MyClass.prototype;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  i = _ref[_i];
  console.log(i);
}

But prototype doesn't have a length property, so, it breaks.

How can I make it with coffeescript?

caarlos0
  • 20,020
  • 27
  • 85
  • 160

1 Answers1

0

The 'secret' is to use the of command when using objects:

console.log i for i of MyClass.prototype
Colin Ross
  • 589
  • 2
  • 12