   constructor: (@ast, @element) ->
 
   addBoundClass: (className) ->
-    @boundClasses or= []
-    if @boundClasses?.indexOf(className) is -1
+    @boundClasses or= new Collection()
+    unless @boundClasses?.includes(className)
       @boundClasses.push(className)
-    @updateClass()
+      @updateClass()
 
   removeBoundClass: (className) ->
-    @boundClasses.splice(@boundClasses.indexOf(className), 1) if @boundClasses
-    @updateClass()
+    if @boundClasses
+      index = @boundClasses.indexOf(className)
+      @boundClasses.delete(className)
+      @updateClass()
 
   setAttributeClasses: (name="__self__", value) ->
     @attributeClasses or= {}

    @children or []

  bindEvent: (event, fun) ->
    @boundEvents or= []
    if event
      @boundEvents.push({ event, fun })
      event.bind(fun)

  unbindEvent: (event, fun) ->
    @boundEvents or= []
    if event
      @boundEvents.splice(@boundEvents.indexOf(fun), 1)
      event.unbind(fun)

  detach: ->

    classes = @ast.classes
    if @attributeClasses
      classes = classes.concat(value) for own _, value of @attributeClasses
    classes = classes.concat(@boundClasses.toArray()) if @boundClasses?.length
    classes.sort()
    if classes.length
      assignUnlessEqual(@element, "className", classes.join(' '))
