Skip to content

Instantly share code, notes, and snippets.

@kentaromiura
Created August 6, 2010 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentaromiura/511069 to your computer and use it in GitHub Desktop.
Save kentaromiura/511069 to your computer and use it in GitHub Desktop.
Private mootator for mooTools 1.2.4
Class.Mutators.Private = function(private) {
var Private = {};
var me = this;
var imp = me.implement;
imp.apply(me, ['~', function() {
var uid = $uid(this);
private = null;
delete Private[uid];
}]);
me.implement = function(key, value) {
if ($type(key) == 'string' && $type(value) == 'function') {
imp.apply(me, [key, function() {
var uid = $uid(this);
var priv = Private[uid] || (Private[uid] = $unlink(private));
var args = $A(arguments);
args.push(priv);
var res = value.apply(this, args);
return res;
}]);
return me;
}
return imp.apply(me, arguments);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment