summaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-01-10 10:27:00 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-01-10 10:27:00 -0800
commit22a8989123519263e2285b1dd71497ddf4469d53 (patch)
tree5f244af93deeb567809c4b1539a034917c014224 /js/lib
parent24c277e407fd328171602e397f48cbd76e135120 (diff)
Made NodeWalker a regular function returning an object.
Diffstat (limited to 'js/lib')
-rw-r--r--js/lib/node.js20
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;
};