[Pkg-javascript-commits] [dojo] 07/11: Porting dojo.clone() changes from the trunk. Refs #5284.
David Prévot
taffit at moszumanska.debian.org
Mon May 11 20:11:45 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag 1.0.2
in repository dojo.
commit ed093d366c8d93f057ee85a3dcc93229751a52e8
Author: Eugene Lazutkin <eugene at lazutkin.com>
Date: Mon Dec 10 19:43:52 2007 +0000
Porting dojo.clone() changes from the trunk. Refs #5284.
git-svn-id: http://svn.dojotoolkit.org/src/branches/1.0/dojo/trunk@11775 560b804f-0ae3-0310-86f3-f6aa0a117693
---
_base/lang.js | 28 ++++++++++++++++------------
tests/_base/lang.js | 22 +++++++++++++++++++++-
2 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/_base/lang.js b/_base/lang.js
index e586998..533466c 100644
--- a/_base/lang.js
+++ b/_base/lang.js
@@ -214,20 +214,24 @@ dojo.clone = function(/*anything*/ o){
r.push(dojo.clone(o[i]));
}
return r; // Array
- }else if(dojo.isObject(o)){
- if(o.nodeType && o.cloneNode){ // isNode
- return o.cloneNode(true); // Node
- }else{
- var r = new o.constructor(); // specific to dojo.declare()'d classes!
- for(var i in o){
- if(!(i in r) || r[i] != o[i]){
- r[i] = dojo.clone(o[i]);
- }
- }
- return r; // Object
+ }
+ if(!dojo.isObject(o)){
+ return o; /*anything*/
+ }
+ if(o.nodeType && o.cloneNode){ // isNode
+ return o.cloneNode(true); // Node
+ }
+ if(o instanceof Date){
+ return new Date(o.getTime()); // Date
+ }
+ // Generic objects
+ var r = new o.constructor(); // specific to dojo.declare()'d classes!
+ for(var i in o){
+ if(!(i in r) || r[i] != o[i]){
+ r[i] = dojo.clone(o[i]);
}
}
- return o; /*anything*/
+ return r; // Object
}
dojo.trim = function(/*String*/ str){
diff --git a/tests/_base/lang.js b/tests/_base/lang.js
index 3aed11d..e41f4f5 100644
--- a/tests/_base/lang.js
+++ b/tests/_base/lang.js
@@ -151,6 +151,26 @@ tests.register("tests._base.lang",
}
var obj2 = thinger.apply(this, obj1);
t.assertEqual(obj1[0], obj2[0]);
- }
+ },
+
+ function clone(t) {
+ var obj1 = {foo: 'bar', answer: 42, jan102007: new Date(2007, 0, 10),
+ baz: {
+ a: null,
+ b: [
+ 1, "b", 2.3, true, false
+ //, function(){ return 4; }, /\d+/gm
+ ]
+ }
+ };
+ var obj2 = dojo.clone(obj1);
+ t.assertEqual(obj1.foo, obj2.foo);
+ t.assertEqual(obj1.answer, obj2.answer);
+ t.assertEqual(obj1.jan102007, obj2.jan102007);
+ t.assertEqual(obj1.baz.a, obj2.baz.a);
+ for(var i = 0; i < obj1.baz.b.length; ++i){
+ t.assertEqual(obj1.baz.b[i], obj2.baz.b[i]);
+ }
+ }
]
);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git
More information about the Pkg-javascript-commits
mailing list