This is being called within a $.each, this creates a closure for each so they get "type" before the loop is done and sets this to the last value.

Try it without the closure :)