日期:2014-05-16  浏览次数:20449 次

ExtJs 提供的 javascript克隆对象的方法

/**
?*?Clone?Function
?*?@param?{Object/Array}?o?Object?or?array?to?clone
?*?@return?{Object/Array}?Deep?clone?of?an?object?or?an?array
?*?@author?Ing.?Jozef?Sakálo?
?*/
Ext.ux.util.clone?=?function(o
)?{
????if(!
o?||?'object'?!==?typeof?o
)?{
????????return?
o
;
????}
????if(
'function'?===?typeof?o
.clone)?{
????????return?
o
.clone();
????}
????var?
c?=?'[object?Array]'?===?Object.prototype.toString.call(o
)???[]?:?{};
????var?
p,?v
;
????for(
p?in?o
)?{
????????if(
o.hasOwnProperty(p
))?{
????????????
v?=?o[p
];
????????????if(
v?&&?'object'?===?typeof?v
)?{
????????????????
c[p]?=?Ext.ux.util.clone(v
);
????????????}
????????????else?{
????????????????
c[p]?=?v