Daniel Chatfield
Daniel Chatfield

Reputation: 2970

How to do if x in y in coffeescript

I have this coffeescript:

y = Object
y.x = true;
result = false
if 'x' in y
    result = true

Which generates this javascript:

var result, y,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) {   if (i in this && this[i] === item) return i; } return -1; };

y = Object;

y.x = true;

result = false;

if (__indexOf.call(y, 'x') >= 0) {
   result = true;
}

Clearly the result should be true but the javascript generated does not return this result. I know I could just escape the section as javascript but that seems hacky. Any help is greatly appreciated.

Upvotes: 1

Views: 313

Answers (1)

Daniel Chatfield
Daniel Chatfield

Reputation: 2970

Just found out that I need to use 'of' instead of 'in'.

Upvotes: 2

Related Questions