Skip to content

Instantly share code, notes, and snippets.

@LeoDT
Created May 7, 2013 07:30
Show Gist options
  • Save LeoDT/5530844 to your computer and use it in GitHub Desktop.
Save LeoDT/5530844 to your computer and use it in GitHub Desktop.
backbone like event map
$.fn.event_map = function(map){
var el = this;
$.each(map, function(k, v){
var event = k.slice(0, k.indexOf(" ")),
selector = k.slice(k.indexOf(" ") + 1, k.length);
if(event && typeof v === "function"){
if(k.indexOf(" ") != -1){
el.on(event, selector, v);
}
else{
el.on(k, v);
}
}
else{
throw "need a event and function";
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment