-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXUtils.js
More file actions
57 lines (50 loc) · 1.78 KB
/
XUtils.js
File metadata and controls
57 lines (50 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(function( w ){
var XUtils = new XClass({
singleton : true,
statics : {
typeOf : function( object ){
return Object.prototype.toString.call( object).slice( 8 , -1 ).toLowerCase();
},
clone : function( object ){
if( object == null )
return object;
var type = XUtils.typeOf( object );
if( object.nodeType && object.cloneNode )
return object.cloneNode( true );
switch( type ){
case 'date':
return new Date( object.getTime() );
case 'array':
var c = [];
XUtils.array.forEach( object , function( o , i ){
c[ i ] = XUtils.clone( o );
});
return c;
case 'object':
var c = {};
XUtils.object.each( object , function( k , v ){
c[ k ] = XUtils.clone( v );
} );
return c;
default :
return object;
}
},
object : {
each : XClass.utils.objectEach
},
array : {
forEach : XClass.utils.arrayEach
},
each : function( object , func ){
if( XUtils.typeOf(object) === 'array' )
XUtils.array.forEach( object , func );
else
XUtils.object.each( object , func );
},
ns : XClass.utils.ns,
namespace : XClass.utils.ns
}
});
w.XUtils = XUtils;
})(window);