root / trunk / web / dojo / dojox / lang / utils.js @ 9
History | View | Annotate | Download (1.65 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.lang.utils"]){ |
||
9 | dojo._hasResource["dojox.lang.utils"]=true; |
||
10 | dojo.provide("dojox.lang.utils");
|
||
11 | (function(){
|
||
12 | var _1={},du=dojox.lang.utils,_2=Object.prototype.toString;
|
||
13 | var _3=function(o){ |
||
14 | if(o){
|
||
15 | switch(_2.call(o)){
|
||
16 | case "[object Array]": |
||
17 | return o.slice(0); |
||
18 | case "[object Object]": |
||
19 | return dojo.delegate(o);
|
||
20 | } |
||
21 | } |
||
22 | return o;
|
||
23 | }; |
||
24 | dojo.mixin(du,{coerceType:function(_4,_5){ |
||
25 | switch(typeof _4){ |
||
26 | case "number": |
||
27 | return Number(eval("("+_5+")")); |
||
28 | case "string": |
||
29 | return String(_5);
|
||
30 | case "boolean": |
||
31 | return Boolean(eval("("+_5+")")); |
||
32 | } |
||
33 | return eval("("+_5+")"); |
||
34 | },updateWithObject:function(_6,_7,_8){ |
||
35 | if(!_7){
|
||
36 | return _6;
|
||
37 | } |
||
38 | for(var x in _6){ |
||
39 | if(x in _7&&!(x in _1)){ |
||
40 | var t=_6[x];
|
||
41 | if(t&&typeof t=="object"){ |
||
42 | du.updateWithObject(t,_7[x],_8); |
||
43 | }else{
|
||
44 | _6[x]=_8?du.coerceType(t,_7[x]):_3(_7[x]); |
||
45 | } |
||
46 | } |
||
47 | } |
||
48 | return _6;
|
||
49 | },updateWithPattern:function(_9,_a,_b,_c){ |
||
50 | if(!_a||!_b){
|
||
51 | return _9;
|
||
52 | } |
||
53 | for(var x in _b){ |
||
54 | if(x in _a&&!(x in _1)){ |
||
55 | _9[x]=_c?du.coerceType(_b[x],_a[x]):_3(_a[x]); |
||
56 | } |
||
57 | } |
||
58 | return _9;
|
||
59 | },merge:function(_d,_e){ |
||
60 | if(_e){
|
||
61 | var _f=_2.call(_d),_10=_2.call(_e),t,i,l,m;
|
||
62 | switch(_10){
|
||
63 | case "[object Array]": |
||
64 | if(_10==_f){
|
||
65 | t=new Array(Math.max(_d.length,_e.length));
|
||
66 | for(i=0,l=t.length;i<l;++i){ |
||
67 | t[i]=du.merge(_d[i],_e[i]); |
||
68 | } |
||
69 | return t;
|
||
70 | } |
||
71 | return _e.slice(0); |
||
72 | case "[object Object]": |
||
73 | if(_10==_f&&_d){
|
||
74 | t=dojo.delegate(_d); |
||
75 | for(i in _e){ |
||
76 | if(i in _d){ |
||
77 | l=_d[i]; |
||
78 | m=_e[i]; |
||
79 | if(m!==l){
|
||
80 | t[i]=du.merge(l,m); |
||
81 | } |
||
82 | }else{
|
||
83 | t[i]=dojo.clone(_e[i]); |
||
84 | } |
||
85 | } |
||
86 | return t;
|
||
87 | } |
||
88 | return dojo.clone(_e);
|
||
89 | } |
||
90 | } |
||
91 | return _e;
|
||
92 | }}); |
||
93 | })(); |
||
94 | } |