Coming to JavaScript from C# and C/C++ world, I'm used to decorating my private members with underscore.
But a couple of JS devs I know have told me it's not common in JS world, and my code looks "weird" to them. I got intrigued and interviewed about 4-5 more JS devs and they all confirmed.
Just to be clear, her's my code:
var myObject = new myClass("some value");
function myClass(param) {
var _privateVar = param;
this.publicMethod = function() {
alert(_privateVar);
}
}
Now my questions are:
Is this true? Should I stop writing code like this - note, I ask only in the scope of hiring, just wanna be sure that newcomers won't find our existing code "weird"
If it is true, is there any explanation? Or it sorta "historically" happened? Not trying to start a flame-war or anything, just curious, I'm fine with dumping my old habits.
UPDATE
OK, maybe I shouldn't call it "private" variable b/c it's actually a "local" variable... But you know what I mean. I need to be able to quickly distinguish variable's scope, by simply looking at it. How "local" are the vars? Are they local to publicMethod or to the whole myClass? That's the reason of using underscore, not the actual "privacy"