Calling dynamic jQuery plugin with dynamic parameters in Javascript -
suppose need dynamically construct plugin calls such
$('#mydiv').myplugin({a:'a',b:'b'});
will like:
function funccallbuilder(selector, func, opts){ //dynamically construct plugin call here }
using:
funccallbuilder('#mydiv', 'myplugin', {a:'a',b:'b'});
can point out correct way of doing this?
not sure if understand question, if want first , third code snippet have same effect, use apply:
function funccallbuilder(selector, func, opts){ func.apply($(selector), [opts]); }
or, if want pass function string instead of function object (not point imho):
function funccallbuilder(selector, func, opts){ $.fn[func].apply($(selector), [opts]); }
Comments
Post a Comment