These 2 functions can be used by you, but as they are not documented, they
might change over time, we don't recommend that you use it. Use it at your
own risk.
The *overloadSetter* grabs a normal function that accepts 2 arguments, a key
and a value and turns it into a function that can accept an object as the
parameters too.
so, for example:
Function.prototype.extend = function(key, value){
this[key] = value;
};
This will make the extend function accept a key and a value that will be
attached to "this" function. Like this:
function(){}.extend('key', 'value');
When you do:
Function.prototype.extend = function(key, value){
this[key] = value;
}.overloadSetter();
The function will be able to accept an object too and it will be possible to
use it like this:
function(){}.extend({'key': 'value'});
The *overloadGetter* function will transform a function that receives one
string and returns one value, like the get function:
get: function(prop){
var property = Element.Properties[prop];
return (property && property.get) ? property.get.apply(this) :
this.getProperty(prop);
}.overloadGetter()
Into a function that can accept an array or multiple arguments, so you can
use it this:
get('p1', 'p2', 'p3', ...) or get(['p1', 'p2', 'p3', ...])
Hope it's clear.
Again, avoid using it for public projects.
--
Fábio Miranda Costa
front...@portalpadroes
Globo.com
*github:* fabiomcosta
*twitter:* @fabiomiranda
*ramal:* 6410
On Sun, Oct 24, 2010 at 11:15 AM, HENG <[email protected]> wrote:
>
> Hello guys:
>
> I am very confused about Mootools 1.3 source code and especailly the code
> as follows:
>
>
> 1. var enumerables = true;
> 2. for (var i in {
> 3. toString: 1
> 4. }) enumerables = null;
> 5. if (enumerables) enumerables = ['hasOwnProperty', 'valueOf',
> 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString',
> 'constructor'];
> 6. Function.prototype.overloadSetter = function(usePlural) {
> 7. var self = this;
> 8. return function(a, b) {
> 9. if (a == null) return this;
> 10. if (usePlural || typeof a != 'string') {
> 11. for (var k in a) self.call(this, k, a[k]);
> 12. if (enumerables) for (var i = enumerables.length;
> i--;) {
> 13. k = enumerables[i];
> 14. if (a.hasOwnProperty(k)) self.call(this, k,
> a[k]);
> 15. }
> 16. } else {
> 17. self.call(this, a, b);
> 18. }
> 19. return this;
> 20. };
> 21. };
> 22. Function.prototype.overloadGetter = function(usePlural) {
> 23. var self = this;
> 24. return function(a) {
> 25. var args, result;
> 26. if (usePlural || typeof a != 'string') args = a;
> 27. else if (arguments.length > 1) args = arguments;
> 28. if (args) {
> 29. result = {};
> 30. for (var i = 0; i < args.length; i++)
> result[args[i]] = self.call(this, args[i]);
> 31. } else {
> 32. result = self.call(this, a);
> 33. }
> 34. return result;
> 35. };
> 36. };
>
> 'Function.property,overloadSetter' and 'Function.property.overloadGetter'
> .... I found they really important function in Mootools 1.3, but no document
> and no explaintion about it........How does it works with Mootools core? Who
> can give me an explaintion?
>
> And more, I really have no idea about 'var enumerables = true;' why do we
> need enumerable? I know it has some different in ECMA-262 Javascript, But I
> really do not know why Mootools use it....
>
> Anyone can understand the code....I will admire you so much, because I do
> not understand it....
>
> Thank you....
>
>
> --
> --------------------------------------------------------------------
> HengZhou
> ---------------------------------------------------------------------
> --
>
>