Showing posts with label JsLint. Show all posts
Showing posts with label JsLint. Show all posts

Unexpected 'in'. Compare with undefined, or use the hasOwnProperty method instead

Unexpected 'in'. Compare with undefined, or use the hasOwnProperty method instead.

Problem: JsLint Confusion

I don't understand why JsLint is giving me this error message: Unexpected 'in'. Compare with undefined, or use the hasOwnProperty method instead.(see infix_in at http://www.jslint.com/msgs.html). The "in" operator seems to be very clearly defined. There appear to be only three outcomes for 'someProperty' in anObject which is one of: true, false, or a TypeError exception is thrown. When it evaluates to true, then there is definitely 'someProperty' in anObject. When it evaluates to false there is definitely not 'someProperty' in anObject. When a TypeError is thrown there is definitely not 'someProperty' in anObject because anObject is either null or it isn't an object at all. This all seems very clear to me. When I want to know if an object has a property and, I don't care if that property is the object's own property or being inherited and, I don't care what the value of the property is, then I simply look for 'someProperty' in anObject.