adt.js
function (field) {
      var ctr = this.constructor;
      var names = ctr.__names__;
      var constraints = ctr.__constraints__;
      if (typeof field === 'number') {
        if (field < 0 || field > names.length - 1) {
          throw new Error('Field index out of range: ' + field);
        }
        field = names[field];
      } else {
        if (!constraints.hasOwnProperty(field)) {
          throw new Error('Field name does not exist: ' + field);
        }
      }
      return this[field];
    }
function (field) {
      var ctr = this.constructor;
      var names = ctr.__names__;
      var constraints = ctr.__constraints__;
      if (typeof field === 'number') {
        if (field < 0 || field > names.length - 1) {
          throw new Error('Field index out of range: ' + field);
        }
        field = names[field];
      } else {
        if (!constraints.hasOwnProperty(field)) {
          throw new Error('Field name does not exist: ' + field);
        }
      }
      return this[field];
    }
function ( field ) { var ctr = this . constructor ; var names = ctr . __names__ ; var constraints = ctr . __constraints__ ; if ( typeof field === 'number' ) { if ( field < 0 || field > names . length - 1 ) { throw new Error ( 'Field index out of range: ' + field ) ; } field = names [ field ] ; } else { if ( ! constraints . hasOwnProperty ( field ) ) { throw new Error ( 'Field name does not exist: ' + field ) ; } } return this [ field ] ; }
Overloaded to take either strings or numbers. Throws an error if the key can't be found.
Overloaded to take either strings or numbers . Throws an error if the key can t be found .