cmark

My personal build of CMark ✏️

Commit
22a8989123519263e2285b1dd71497ddf4469d53
Parent
24c277e407fd328171602e397f48cbd76e135120
Author
John MacFarlane <jgm@berkeley.edu>
Date

Made NodeWalker a regular function returning an object.

Diffstat

1 file changed, 11 insertions, 9 deletions

Status File Name N° Changes Insertions Deletions
Modified js/lib/node.js 20 11 9
diff --git 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;
 };