JavaScript – How to Name a Private Method in a Language Without Privacy Support

classjavascriptnaming

What's the coding standard for naming a private method in a language which does not have the private modifier? Specifically, I am talking about Javascript. Below I've placed an underscore at the end of my private method's name, but a colleague told me that underscore is usually for class fields.

var MyClass = Class.create({
    initialize: function() {
        alert('constructor');
    },
    publicMethod: function() {
        alert('i am public');
    },
    privateMethod_: function() {
        alert('i am private');
    }
});

Best Answer

As everyone told you in a comments, most people(and some languages) use single underscore.