[Pkg-javascript-commits] [ltx] 440/469: use original constructor for the clone
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:03:36 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository ltx.
commit fd9119fbc64e92d556d370d66cef7a4ca17545ab
Author: Sonny Piers <sonny at fastmail.net>
Date: Thu Mar 31 14:26:36 2016 +0200
use original constructor for the clone
---
lib/Element.js | 9 ++-------
test/element-test.js | 10 ++++++++++
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/lib/Element.js b/lib/Element.js
index fe6b6ad..f5bfbfa 100644
--- a/lib/Element.js
+++ b/lib/Element.js
@@ -237,14 +237,9 @@ Element.prototype.up = function () {
return this
}
-Element.prototype._getElement = function (name, attrs) {
- var element = new Element(name, attrs)
- return element
-}
-
/** create child node and return it */
Element.prototype.c = function (name, attrs) {
- return this.cnode(this._getElement(name, attrs))
+ return this.cnode(new Element(name, attrs))
}
Element.prototype.cnode = function (child) {
@@ -294,7 +289,7 @@ Element.prototype.remove = function (el, xmlns) {
* doing. Building XML with ltx is easy!
*/
Element.prototype.clone = function () {
- var clone = this._getElement(this.name, this.attrs)
+ var clone = new this.constructor(this.name, this.attrs)
for (var i = 0; i < this.children.length; i++) {
var child = this.children[i]
clone.cnode(child.clone ? child.clone() : child)
diff --git a/test/element-test.js b/test/element-test.js
index 6bef848..b33db92 100644
--- a/test/element-test.js
+++ b/test/element-test.js
@@ -2,6 +2,7 @@
var vows = require('vows')
var assert = require('assert')
+var inherits = require('inherits')
var ltx = require('..')
var Element = ltx.Element
@@ -200,6 +201,15 @@ vows.describe('Element').addBatch({
assert.equal(orig.getChildText('content'), 'foo')
assert.equal(clone.children[0].name, 'description')
assert.equal(clone.getChildText('description'), 'foobar')
+ },
+ 'use original constructor for the clone': function () {
+ var Foo = function (name, attrs) {
+ Element.call(this, name, attrs)
+ }
+ inherits(Foo, Element)
+ var foo = new Foo()
+ assert(foo.clone() instanceof Element)
+ assert(foo.clone() instanceof Foo)
}
},
'children': {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git
More information about the Pkg-javascript-commits
mailing list