且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery相当于Ruby的.send()方法

更新时间:2022-05-09 04:37:09

您可以使用方括号 [] 访问javascript对象的任何成员(包括函数)然后使用正常括号调用它()。这是一个非常简化的例子

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]();​​​​​​