struct.js
function(receiver, name, val) {
      if (name in props) {

        // Check property descriptor
        var desc = this.getOwnPropertyDescriptor(name);
        if (desc && !desc.writable) {
          throw name + ' is not writable property';
        }

        if (props[name].nullable === false && isNullOrUndefined(val)) {
          throw name + ' is not allowd null or undefined';
        }

        // Check type match
        var type = props[name].type;
        if (isNullOrUndefined(val) || Struct.isStructType(type, val) || Struct.util.isType(type, val)) {
          // OK
        } else {
          throw name + ' must be ' + props[name].type + ' type';
        }

        if (props[name].cond && !props[name].cond(val)) {
          throw 'Invalid value:' + name + '=' + String(val);
        }

        obj[name] = val;
        return true;
      } else {
        throw name + ' is not defined in this struct';
      }
    }
function(receiver, name, val) {
      if (name in props) {

        // Check property descriptor
        var desc = this.getOwnPropertyDescriptor(name);
        if (desc && !desc.writable) {
          throw name + ' is not writable property';
        }

        if (props[name].nullable === false && isNullOrUndefined(val)) {
          throw name + ' is not allowd null or undefined';
        }

        // Check type match
        var type = props[name].type;
        if (isNullOrUndefined(val) || Struct.isStructType(type, val) || Struct.util.isType(type, val)) {
          // OK
        } else {
          throw name + ' must be ' + props[name].type + ' type';
        }

        if (props[name].cond && !props[name].cond(val)) {
          throw 'Invalid value:' + name + '=' + String(val);
        }

        obj[name] = val;
        return true;
      } else {
        throw name + ' is not defined in this struct';
      }
    }
function ( receiver , name , val ) { if ( name in props ) { // Check property descriptor var desc = this . getOwnPropertyDescriptor ( name ) ; if ( desc && ! desc . writable ) { throw name + ' is not writable property' ; } if ( props [ name ] . nullable === false && isNullOrUndefined ( val ) ) { throw name + ' is not allowd null or undefined' ; } // Check type match var type = props [ name ] . type ; if ( isNullOrUndefined ( val ) || Struct . isStructType ( type , val ) || Struct . util . isType ( type , val ) ) { // OK } else { throw name + ' must be ' + props [ name ] . type + ' type' ; } if ( props [ name ] . cond && ! props [ name ] . cond ( val ) ) { throw 'Invalid value:' + name + '=' + String ( val ) ; } obj [ name ] = val ; return true ; } else { throw name + ' is not defined in this struct' ; } }
Set value.
Check property name if defined and type is matched in advance.
Set value . Check property name if defined and type is matched in advance .