Wylde
08-04-2007, 05:28 PM
1. namespace : function(){
2. var a=arguments, o=null, i, j, d, rt;
3. for (i=0; i<a.length; ++i) {
4. d=a[i].split(".");
5. rt = d[0];
6. eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
7. for (j=1; j<d.length; ++j) {
8. o[d[j]]=o[d[j]] || {};
9. o=o[d[j]];
10. }
11. }
12. },
In this function, why in line 9 the var 'o' is reassigned with o[d[j]] ? if you remove line 9 ,nothing change in the normal workflow.
Suppose Ext.namespace("Ext","Ext.utils");
in the 1st cicle, only the first for it's executed, so o = Ext object.
in the 2nd cicle, the 2nd for it's executed, so o["utils"] = {} ....ok
but in the next line ... o = o["utils"] ?? if so, Ext object it's totally erased... or not ?
thx for reading :)
2. var a=arguments, o=null, i, j, d, rt;
3. for (i=0; i<a.length; ++i) {
4. d=a[i].split(".");
5. rt = d[0];
6. eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
7. for (j=1; j<d.length; ++j) {
8. o[d[j]]=o[d[j]] || {};
9. o=o[d[j]];
10. }
11. }
12. },
In this function, why in line 9 the var 'o' is reassigned with o[d[j]] ? if you remove line 9 ,nothing change in the normal workflow.
Suppose Ext.namespace("Ext","Ext.utils");
in the 1st cicle, only the first for it's executed, so o = Ext object.
in the 2nd cicle, the 2nd for it's executed, so o["utils"] = {} ....ok
but in the next line ... o = o["utils"] ?? if so, Ext object it's totally erased... or not ?
thx for reading :)