Created
March 4, 2011 18:26
-
-
Save kentaromiura/855443 to your computer and use it in GitHub Desktop.
private pattern mutator for Mootools 1.3.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
--- | |
name: kenta.Private | |
description: Private mootator for MooTools 1.3.x | |
license: MIT-style license. | |
copyright: Carlesso Cristian http://mykenta.blogspot.com | |
requires: Class.PatternMutators | |
provides: private pattern mutator, '~' cleanup method. | |
... | |
*/ | |
(function(){ | |
var Private={}; | |
Class.defineMutator(/^private\s(.*)/,function(fn, name){ | |
var getPrivate = function(bind){ | |
var uid= $uid(bind); | |
return Private[uid] || (Private[uid] = {}); | |
}; | |
this.define('~', function() { | |
var uid = $uid(this); | |
delete Private[uid]; | |
}); | |
this.define(name, function(){ | |
var priv = getPrivate(this); | |
var args = Array.from(arguments); | |
args.push(priv); | |
var res = fn.apply(this, args); | |
return res; | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the Private pattern mutator for mootools 1.3.x
it requires the Class.PatternMutators from Mark Obcena
This mutator gives to your objects access to a special object that can't be accessed from other classes,
in order to use this object you only need 4 things:
Example:
run this snippet