Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you apply a jquery function with the function name as a parameter?
    primarykey
    data
    text
    <p>If you have a variable number of jQuery plugins of the format:</p> <pre><code>(function($){ $.fn.toolSet_themeOne = function () { // params }; })(jQuery); (function($){ $.fn.toolSet_themeTwo = function () { // params }; })(jQuery); </code></pre> <p>Where each plugin's definition is not guaranteed to be the same and is likely to contain some degree of variation in name after the underscore, how could these be applied in a situation such as this:</p> <pre><code>var themeApply = function (jQueryCollection, objSettings, pluginName) { // this does not work and reports pluginName is not a function jQueryCollection.pluginName(objSettings); // $.fn[pluginName] is reported as a function }; </code></pre> <p>I thought to use <a href="https://stackoverflow.com/questions/1676583/executing-a-function-by-name-passing-an-object-as-a-parameter">another question</a> as a guide, but don't see how to scope it correctly. Any pointers would be greatly appreciated.</p> <p>Thank you :)</p> <p><strong>EDIT:</strong> For those wondering what function is inside, this is an example (learned from another SO answer for which I cannot find an immediate refrence:</p> <pre><code>(function($){ $.fn.toolSet_themeOne = function () { var methods = [ update: update ]; var init = function (options) { // normal jquery initialisation here }; var update = function (data) { // do something with data // if not initialising, but calling after initialisation }; // what do we do on initialisation? if(arguments.length &gt; 0) { if('string' === typeof(arguments[0]) &amp;&amp; 'undefined' !== typeof(methods[arguments[0]])) { var args = Array.prototype.slice.call(arguments); args = args.shift(); methods[arguments[0]].apply(this,args); } else if('object' === typeof(arguments[0])) { init.apply(this, arguments); } } else { init.apply(this, arguments); } return this; }; })(jQuery); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload