Login Register

Analog to the Crockford Module Pattern in dojo.declare(...)?

Hi All,

I ran across this entry in the YUI blog that describes a pattern for modularizing JS code to the point of having actual private members in a particular chunk of code. I'm wondering, has anyone given any thought to providing similar support for a class defined with dojo.declare?

There is already support for static members by defining functions and members in the 'statics' attribute. Might it be possible to provide a 'private' attribute as well? From the perspective of someone who'd like to use this feature, I'm thinking something along the lines of:

dojo.declare("example.project.MyClass", null
    function() {
         // initialization as usual
    },
{
    private: {
       privateVariable: null,

        privateFunction: function() {
            // implementation
        }
    }

    publicVariable: null,

    publicFunction: function() {
        // implementation
    }
});

I've always thought that not having private members in JavaScript makes maintaining larger projects more of a hassle. Anyone can ignore an underscore character on the front of a function name, after all :) Has this feature been considered or discussed previously?

Thanks,

Peter