JavaScript: "Prevent _ listing in identifiers" as an option in JSLint
I just started writing my own JavaScript Framework (training only) and prefix some private members with _ , for example:
var _isFireBugEnabled = function () {
return (window.console && window.console.firebug);
};
When I ran my code against Crockford JSLint (as always), Recommended Options
I was told that I was not using a _ as an identifier.
My question is: Why is JSLint warning me that you are not using _ as an identifier?
Are there any side effects or implications I'm missing here?
PS. As far as I could scan now, this is not covered in the book
source to share
The reason is that Douglas Crockford hates about 78% of Javascript *. Many people think it's a bit strict, and in fact many libraries use advanced underscores in production code. I don't see anything wrong with that. No side effects.
Also, the "$", not the underscore, was the character allocated for "system" code by the ECMA specification .
from ECMA 262, section 7.6:
This standard specifies one departure from the grammar specified in Unicode Standard: dollar sign ($) and underscore (_) are allowed anywhere in an identifier. The dollar sign is for use only mechanically generated code.
* Note: I really like it. He only really hates half, and he usually has good reasons. I would disagree with Crockford here, but he is usually very right.
source to share
I actually emailed Crockford about this. This was his answer:
I think that _ should be reserved for system code implementation, not used by applications.
I disagree with him somewhat, I tend to use _ to prefix really private members in my classes because it gives me a clue of what is private. Google Caja has some rules about using _, but nothing should cause problems with what you are describing.
source to share