Is there any recommended and elegant way to use Private variables in
MooTools 1.3+ Class?

This is what I found so far:

solution by Mark Obcena (
http://keetology.com/blog/2009/07/23/up-the-moo-herd-iii-its-classy-not-classic
)

which a little of tweaking would look like:

// private
var Private = new Class(function(){
        var secret = "I like bacon";

        Object.append(this, {
                initialize: function(options){
                        console.log("secret is: ", secret);
                        console.log("args are: ", args);
                }
        });

        // have to invoke initalize manually
        this.initialize.apply(this, arguments);

        return this;
});


This is what I came up with, however this works more as static private
variable (quite similar to 
http://stackoverflow.com/questions/6104063/private-properties-in-mootools-1-3-classes)

// static private
var StaticPrivate = (function(){
    var secret = "Chocolate";

    // use `new new Class({})` to return instance
    return new Class({
        initialize: function(options){
            console.log("secret is: ", secret);
            console.log("args are: ", args);
        }
    });
});

There is one more interesting approach:
http://thomasdullnig.blogspot.com/2009/01/private-members-in-mootools-i-do-it-my.html

But I had problems with converting it for MT1.3

Just to make sure: I'm looking for private variables. Using private
methods seems pretty easy using .protect() at the end of the method.

Reply via email to