 #= require ../object
 
 class Batman.Hash extends Batman.Object
+
   class @Metadata extends Batman.Object
     Batman.extend @prototype, Batman.Enumerable
+
     constructor: (@hash) ->
+
     @accessor 'length', ->
       @hash.registerAsMutableSource()
       @hash.length
+
     @accessor 'isEmpty', 'keys', 'toArray', (key) ->
       @hash.registerAsMutableSource()
       @hash[key]()
+
     forEach: -> @hash.forEach(arguments...)
 
   constructor: ->
     @meta = new @constructor.Metadata(this)
-    Batman.SimpleHash.apply(@, arguments)
+    Batman.SimpleHash.apply(this, arguments)
     super
 
   Batman.extend @prototype, Batman.Enumerable
   propertyClass: Batman.Property
 
   @defaultAccessor =
+    cache: false
     get: Batman.SimpleHash::get
+
     set: @mutation (key, value) ->
-      result = Batman.SimpleHash::set.call(@, key, value)
-      @fire 'itemsWereAdded', key
+      result = Batman.SimpleHash::set.call(this, key, value)
+      @fire('itemsWereAdded', key)
+
       result
+
     unset: @mutation (key) ->
-      result = Batman.SimpleHash::unset.call(@, key)
-      @fire 'itemsWereRemoved', key if result?
+      result = Batman.SimpleHash::unset.call(this, key)
+      @fire('itemsWereRemoved', key) if result?
       result
-    cache: false
 
   @accessor @defaultAccessor
 

    do (k) =>
      @prototype[k] = ->
        @registerAsMutableSource()
        Batman.SimpleHash::[k].apply(@, arguments)

    @prevent 'change'
    @prevent 'itemsWereAdded'
    @prevent 'itemsWereRemoved'

    try
      block.call(this)
    finally
      @allow 'change'
      @allow 'itemsWereAdded'
      @allow 'itemsWereRemoved'

  clear: @mutation ->
    keys = @keys()
    @_preventMutationEvents -> @forEach (k) => @unset(k)
    result = Batman.SimpleHash::clear.call(this)

    @fire('itemsWereRemoved', keys...)
    result

  update: @mutation (object) ->
    addedKeys = []
    @_preventMutationEvents ->
      Batman.forEach object, (k, v) =>
        addedKeys.push(k) unless @hasKey(k)
        @set(k,v)

    @fire('itemsWereAdded', addedKeys...) if addedKeys.length > 0

  replace: @mutation (object) ->
    addedKeys = []
    removedKeys = []
