     result = isObject aValue
     if result
       if aOptions and aOptions.attributes
-        for vName, vType of aOptions.attributes
+        for vName, vType of aOptions.attributes.value()
           if vType.writable and !vType.set and aValue[vName] isnt undefined
             aValue[vName] = vType.toValue aValue[vName]
           if not vType.validate aValue[vName], false

  #TODO: maybe should use Attributes class and put this method into it.
  attrKeys: ->
    result = []
    for k,v of @attributes
      result.push v.name || k if v.enumerable isnt false
    result
  attrOwnPropertyNames: ->
    result = []
    for k,v of @attributes
      result.push v.name
    result
  # Returns

      type: 'Object'
      assigned: '$_attributes' # this should define the non-enumerable `$_attributes` property.
      assign: (value, dest, src, key)->
         dest.attributes.assign(value) if (dest instanceof ObjectType) and dest.attributes?
    $_attributes:
      value: new ObjectAttributes
    strict:
      type: 'Boolean'

  #@defaultType: defaultType.type
  oldRegister = @register
  @register: (aClass)->
    # TODO: howto hook to the ObjectAttributes?
    oldRegister.apply ObjectType, arguments

  defineAttribute: (aName, aOptions, aAttributes)->
    @attributes.defineAttribute(aName, aOptions, aAttributes)

  defineAttributes: (aAttributes, result)->
    @attributes.defineAttributes(aAttributes, result)

  _toObject:(aOptions, aNameRequired)->
    result = super
    result.attributes = vAttrs = {}
    #   delete aOptions.name
    for k,v of @attributes.value()
      vAttrs[k] = t = v.toObject(null, false)
      #delete t[NAME]
      vAttrs[k] = t.type if getObjectKeys(t).length is 1
