Created
December 15, 2011 22:35
-
-
Save ralphholzmann/1483260 to your computer and use it in GitHub Desktop.
Templated event bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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