'use strict';

(function () {

  function Jarg (argv, children, depth, name, value) {
    var self = this;

    self._argv = argv;
    self._children = children;
    self._depth = depth || 0;

    self._name = name || null;
    self._value = value || null;

    self._commands = {};
    self._kwargs = {};
    self._flags = {};
    self._args = {};

    function addNode (node) {
      var type = node._type;

      if (node.name in self['_' + type + 's']) {
        throw new Error('Duplicate ' + type + ' \'' + node.name + '\' in tree at depth ' + self._depth);
      }

      self['_' + type + 's'][node.name] = node;
    }

    for (var i = 0; i < self._children.length; i += 1) {
      var node = self._children[i];

      switch (node._type) {
        case 'command':
        case 'kwarg':
        case 'flag':
        case 'arg':
          addNode(node);
          break;
        default:
          throw new Error('Unknown node type \'' + node._type + '\' in tree at depth ' + self._depth);
      }
    }
  }

  Jarg.prototype.name = function value () {
    return this._name;
  };

  Jarg.prototype.value = function value () {
    return this._value;
  };

  Jarg.prototype.command = function command (query) {
    var argv = [].concat(this._argv);
    var commandName = argv.shift();

    if (!query) {
      if (commandName in this._commands) {
        return new Jarg(argv, this._commands[commandName].children, this._depth + 1, commandName, true);
      }

      return new Jarg([], [], this._depth + 1);
    }

    if (!(query in this._commands)) {
      throw new Error('Command \'' + query + '\' is not defined in tree at depth ' + this._depth);
    }

    for (var key in this._commands) {
      if (key === query && key === commandName) {
        return new Jarg(argv, this._commands[commandName].children, this._depth + 1, commandName, true);
      }
    }

    return new Jarg([], [], this._depth + 1);
  };

  module.exports = Jarg;

})();

@@ -1209,24 +1209,46 @@
 d (query) %7B%0A
+    var self = this;%0A%0A
     var argv
@@ -1260,20 +1260,20 @@
 .concat(
-this
+self
 ._argv);
@@ -1349,28 +1349,28 @@
 mandName in 
-this
+self
 ._commands) 
@@ -1393,36 +1393,36 @@
  new Jarg(argv, 
-this
+self
 ._commands%5Bcomma
@@ -1431,36 +1431,36 @@
 Name%5D.children, 
-this
+self
 ._depth + 1, com
@@ -1507,36 +1507,36 @@
 ew Jarg(%5B%5D, %5B%5D, 
-this
+self
 ._depth + 1);%0A  
@@ -1555,28 +1555,28 @@
 (!(query in 
-this
+self
 ._commands))
@@ -1663,20 +1663,20 @@
 pth ' + 
-this
+self
 ._depth)
@@ -1704,20 +1704,20 @@
  key in 
-this
+self
 ._comman
@@ -1802,20 +1802,20 @@
 g(argv, 
-this
+self
 ._comman
@@ -1840,20 +1840,20 @@
 ildren, 
-this
+self
 ._depth 
@@ -1920,20 +1920,20 @@
 %5B%5D, %5B%5D, 
-this
+self
 ._depth 

Assign this to self