jQuery prependEvent in 5 lines of coffeescript
Works on jQuery 1.9.
$.fn.prebind = (name, handler) ->
@on name, handler
@each ->
handlers = $._data(@, 'events')[name.split('.')[0]]
# move to the beginning
handlers.splice 0, 0, handlers.pop()
This uses internal API ($._data) and might break in the future versions of jQuery
Written by Gleb Mazovetskiy
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#