Oct 10 2008

0

Mootools Privates Class Mutator (update)

Category: Javascript, MootoolsTags:

I saw Daniel Steigerwald’s concept within one of the comments on Jan’s blog and I liked his approach better. Currently I was passing a string of all the method names I wanted to make private. This had the added complexity of removing the properties from the class. With Daniel’s method just pass a private object. Makes much more sense.

Class.Mutators.Privates = function(self,privates){
	self.initalize = (function(){
		for(prop in privates) this[prop] = privates[prop];
		return self.initialize;
	})();
}

Example usage:

var Secret = new Class({
	Privates : { 
		secret : 'hidden message'
	},
 
	getSecret : function(){
		return secret;
	}
});

Tags:

Leave a Reply