Skip to content

Instantly share code, notes, and snippets.

@ralphholzmann
Created December 15, 2011 22:35
Show Gist options
  • Save ralphholzmann/1483260 to your computer and use it in GitHub Desktop.
Save ralphholzmann/1483260 to your computer and use it in GitHub Desktop.
Templated event bindings
// Lets say you're making a plugin with the typical design of
// passing an object literal of options. Here's what you can do.
$.Controller("myPlugin", { // Static properties
// The options you pass get auto extended over these
defaults: {
className: "default-class"
}
}, { // Prototype properties
// Templated event binding:
// Automatically binds this event to whatever class you passed in,
// or the default.
".{className} click" : function() {
console.log( "you clicked " + this.options.className );
}
});
// Both of these just work
$("#foo").myPlugin();
$("#foo").myPlugin({
className: "my-custom-class"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment