small medium large xlarge

Back to: All Forums  CoffeeScript
11 Feb 2012, 21:49
Achim (6 posts)


what construction must i use that coffeescript compiles to:

if (property in object). When i use the syntax:

if object?.property

it compiles to:

if (object != null ? : void 0)

Anyone can help me?

Sorry my english isn’ the best.

Thank you.

14 Feb 2012, 15:16
Trevor Burnham (53 posts)

What you want is @of@. CoffeeScript’s @of@ operator compiles to JavaScript’s @in@ operator; see section 3.3 for more on @of@ vs. @in@.

You can also write, which means “Is non-null?” @object?.property@ means “Give me if @object@ is non-null.”

15 Feb 2012, 21:23
Achim (6 posts)

Thank you very much.

It was my mistake: I thought as i try if object of property that not compiles to “in” in Javascript. But now it does exactly that what you say. I have your book but till yet i had no time to begin read it, but i look forward to read it.

….But: I have now tried some things. Now i’m confussed that when i ran the construct

if letos of likes

with “coffee file” it comes an error. But it compiles perfectly to Javascript’s “if(letos in likes)” I run coffe-script with node.js on windows xp.

Other constructs runs perfectly but not “if object of property”. Is this normally?

Thank you.

16 Feb 2012, 15:47
Trevor Burnham (53 posts)

Same problem as in the other thread: @letos@ is a variable, not a literal; you want @if ‘letos’ of likes@, or

str = 'letos'
if str of likes
You must be logged in to comment