From bc9241c1ff4eb27545eca30589d973deb79d07e4 Mon Sep 17 00:00:00 2001 From: Mary Rose Cook Date: Tue, 13 Aug 2013 12:50:39 -0400 Subject: [PATCH] Remove clone() methods from List and Generic * Keep all cloning together for readability and interface hiding. --- spec/library.spec.js | 40 ++++++++++++++++++++-------------------- src/library.js | 13 +------------ 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/spec/library.spec.js b/spec/library.spec.js index 05d9dc4..64d147d 100644 --- a/spec/library.spec.js +++ b/spec/library.spec.js @@ -50,10 +50,10 @@ describe('library', function() { var l = new library.List(); l.add("1"); l.add("2"); - expect(l.clone().items()[0]).toEqual("1"); - expect(l.clone().items()[1]).toEqual("2"); - expect(l.clone() !== l).toEqual(true); - expect(l.clone().constructor === library.List).toEqual(true); + expect(library.clone(l).items()[0]).toEqual("1"); + expect(library.clone(l).items()[1]).toEqual("2"); + expect(library.clone(l) !== l).toEqual(true); + expect(library.clone(l).constructor === library.List).toEqual(true); }); it('should clone list inside list', function() { @@ -61,9 +61,9 @@ describe('library', function() { var innerL = new library.List(); innerL.add("1"); l.add(innerL); - expect(l.clone().items()[0].items()[0]).toEqual("1"); - expect(l.clone().items()[0] !== innerL).toEqual(true); - expect(l.clone().items()[0].constructor === library.List).toEqual(true); + expect(library.clone(l).items()[0].items()[0]).toEqual("1"); + expect(library.clone(l).items()[0] !== innerL).toEqual(true); + expect(library.clone(l).items()[0].constructor === library.List).toEqual(true); }); it('should clone generic inside list', function() { @@ -71,9 +71,9 @@ describe('library', function() { var g = new library.Generic(); g.la = "1"; l.add(g); - expect(l.clone().items()[0].la).toEqual("1"); - expect(l.clone() !== l).toEqual(true); - expect(l.clone().items()[0].constructor === library.Generic).toEqual(true); + expect(library.clone(l).items()[0].la).toEqual("1"); + expect(library.clone(l) !== l).toEqual(true); + expect(library.clone(l).items()[0].constructor === library.Generic).toEqual(true); }); }); @@ -82,10 +82,10 @@ describe('library', function() { var g = new library.Generic(); g.one = "1"; g.two = "2"; - expect(g.clone().one).toEqual("1"); - expect(g.clone().two).toEqual("2"); - expect(g.clone() !== g).toEqual(true); - expect(g.clone() instanceof library.Generic).toEqual(true); + expect(library.clone(g).one).toEqual("1"); + expect(library.clone(g).two).toEqual("2"); + expect(library.clone(g) !== g).toEqual(true); + expect(library.clone(g) instanceof library.Generic).toEqual(true); }); it('should clone a list inside a generic', function() { @@ -93,9 +93,9 @@ describe('library', function() { var l = new library.List(); l.add("1"); g.l = l; - expect(g.clone().l.items()[0]).toEqual("1"); - expect(g.clone().l !== l).toEqual(true); - expect(g.clone().l.constructor === library.List).toEqual(true); + expect(library.clone(g).l.items()[0]).toEqual("1"); + expect(library.clone(g).l !== l).toEqual(true); + expect(library.clone(g).l.constructor === library.List).toEqual(true); }); it('should clone generic inside generic', function() { @@ -103,9 +103,9 @@ describe('library', function() { var innerG = new library.Generic(); innerG.one = "1"; g.innerG = innerG; - expect(g.clone().innerG.one).toEqual("1"); - expect(g.clone().innerG !== innerG).toEqual(true); - expect(g.clone().innerG.constructor === library.Generic).toEqual(true); + expect(library.clone(g).innerG.one).toEqual("1"); + expect(library.clone(g).innerG !== innerG).toEqual(true); + expect(library.clone(g).innerG.constructor === library.Generic).toEqual(true); }); }); diff --git a/src/library.js b/src/library.js index 63be07c..687f173 100644 --- a/src/library.js +++ b/src/library.js @@ -107,12 +107,6 @@ } return out; - }, - - clone: function() { - var c = new Generic(); - extendObj(this, c); - return c; } }; @@ -191,16 +185,11 @@ return out; } - }, - - clone: function() { - var c = new List(); - c.data = clone(this.data); - return c; } }; exports.Library.List = List; exports.Library.Generic = Generic; exports.Library.getInitialEnv = getInitialEnv; + exports.Library.clone = clone; // exported for testing })(typeof exports === 'undefined' ? this.Isla : exports);