change code from javascript into coffeescript