From 22a8989123519263e2285b1dd71497ddf4469d53 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 10 Jan 2015 10:27:00 -0800 Subject: Made NodeWalker a regular function returning an object. --- js/lib/node.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/js/lib/node.js b/js/lib/node.js index 84fb122..837f596 100644 --- a/js/lib/node.js +++ b/js/lib/node.js @@ -14,18 +14,12 @@ function isContainer(node) { t === 'Image'); } -function NodeWalker(root) { - this.current = root; - this.root = root; - this.entering = true; -} - -NodeWalker.prototype.resumeAt = function(node, entering) { +var resumeAt = function(node, entering) { this.current = node; this.entering = (entering === true); }; -NodeWalker.prototype.next = function(){ +var next = function(){ var cur = this.current; var entering = this.entering; @@ -56,6 +50,14 @@ NodeWalker.prototype.next = function(){ return {entering: entering, node: cur}; }; +var NodeWalker = function(root) { + return { current: root, + root: root, + entering: true, + next: next, + resumeAt: resumeAt }; +} + function Node(nodeType, sourcepos) { this.t = nodeType; this.parent = null; @@ -154,7 +156,7 @@ Node.prototype.insertBefore = function(sibling) { }; Node.prototype.walker = function() { - var walker = new NodeWalker(this); + var walker = NodeWalker(this); return walker; }; -- cgit v1.2.3