Andrea I like your solution. It's a good hack, but you're just tricking JSLint at that with more complex syntax that it can't figure out that. You're essentially doing the same thing as beofre.
I had this problem, too, and I solved it slightly different. I'll let you know what it is here -- feel free to use this technique if you so choose. There's a link to the sample code below.
I was Initially doing something like:
if ( typeof window !=== 'undefined' )
works, but JSLint complains.
If you change it to the recommended
if ( window !=== undefined )
The trick is to simply use try/catch to attempt to use the variable in question, which works in the above mentioned environments. I saw some main-stream libraries use this type of code in detection logic.
In my case, I was trying to create a log() function that will work in the browser, node, js-shell and jsdb.
console.log() exists in browses and node.
jsdb requires println();
js-shell requires print();
Here's the code with just the log() function:http://jsfiddle.net/kasajian/Fqu63/