Towers of Hanoi as Object

This is just a short demonstration of the ideas of object oriented programming. The object has several methods attached to itself. So the variable "hanoi" comes with the methods "hanoi.ringnum" and "hanoi.pegnum" which are considered part of the interface and with the method "hanoi.field" to store the current values of the towers which the user should not interfere with. For moving a ring from pega to pegb, he should use the command "hanoi.move(pega,pegb);". The methods "hanoi.move" and "hanoi.display" are preprogrammed and part of the object. Here the sample code of "hanoi.move"; the name of the function in this implementation ("hanmove") is hidden away from the user.
  function hanmove(a,b)
    { this.movenum++;
      if ((a<this.pegnum) && (b<this.pegnum) &&
          (this.field[a].length>0) &&
          ((this.field[b].length==0) ||
           (this.field[a][this.field[a].length-1]<
            this.field[b][this.field[b].length-1])))
            { this.field[b].push(this.field[a].pop()); }
      else { document.write("Illegal Move.<br>"); }
      return; }
The function "hanoimake" is necessary to create the objects which do not exist before. The methods "hanoi.move" and "hanoi.display" use the parameter "this" to create it. In the function hanoimake, the methods are defined:
  function hanoimake(m,n)
    { var k;
      this.pegnum = m;
      this.ringnum = n;
      this.field = new Array(m);
      this.move = hanmove;
      this.movenum = 0;
      this.display = handisplay;
      for (k=0;k<m;k++)
        { this.field[k] = new Array(); }
      for (k=0;k<n;k++)
        { this.field[0].push(n-k); }
      return; }
Note that the part "hanoi" in the name comes from the variable "hanoi", if the user would name it differently the name of the object would be different.

The first three functions are part of the implementation which should normally be hidden away from the user. The things below refer to what the user has done with these provided functions and are his application programs for the given object.