'in' operator doesn't guard against non arrays
123 in undefined
throws Array.prototype.indexOf called on null or undefined whereas it should return undefined
No, it shouldn't. in operator in coffeescript is equal to indexOf in javascript. And in javascript you will get same error. I think you can close it.
Agreed. We don't do "defensive" programming in any construct that I'm aware of.
Any value in a defensive version of in? Something like 123 in? undefined.
Something like 123 in? undefined
Yeah, that would be nice
Yeah, that would be nice
As i know ? operator works only with variables.
And you can get same result by 123 in ar if ar?.
And you can get same result by 123 in ar if ar?.
that wouldn't check for an Array.
We don't do "defensive" programming
That's a real shame. Why not?
This is issue has kind of been filed a few times before - once by me: #3650
I still think it's frustrating when in as a keyword could instead invoke a helper that checks with .indexOf() for an Array or walks through all the key-value pairs for an Object. in should be more general - not Array-specific. I doubt it would even matter performance-wise.
You can use this very simple pattern:
propertyName in (array ? [])
You should always know if a value you are working with is potentially null/undefined.