I am currently developing a jQuery plugin where I would like to dismiss an element but have the way it is dismissed (slideUp, hide, and other jQuery methods) specified as an option.
For example, someone will be able to specify:
$('element').plugin({style: "slideUp", speed: 300});
and it will call slideUp on the given element.
This is a simplified example and the plugin will do a lot more but I was just wondering if something like this was possible in JavaScript / jQuery. As a parallel I am looking for something much like Ruby's .send() method.
Thanks!
EDIT: I did find this plugin which does something similar to what I am looking for but I would love if there was some way to do this without including another plugin.
You can access any member of a javascript object (including functions) using the square brackets []
And then call that, with the normal parenthesis ()
. Here's a very simplified example
var test = {
slide: function() {alert('slide');},
fade: function() {alert('fade');}
}
var style = "slide"; // or 'fade'
test[style]();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With