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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#