diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-01-10 10:27:00 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-01-10 10:27:00 -0800 |
commit | 22a8989123519263e2285b1dd71497ddf4469d53 (patch) | |
tree | 5f244af93deeb567809c4b1539a034917c014224 /js/lib/node.js | |
parent | 24c277e407fd328171602e397f48cbd76e135120 (diff) |
Made NodeWalker a regular function returning an object.
Diffstat (limited to 'js/lib/node.js')
-rw-r--r-- | js/lib/node.js | 20 |
1 files 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; }; |