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
---------------------------------------------------------------------
--