javascript - jquery plugin, boolean callback parameter -


i trying pass boolean parameter callback inside jquery plugin parameter undefined.

the onswitch callback parameter should alternate between true , false each time link clicked. using debugger can see value passed callback call function defined true or false inside callback implementation turns undefined.

i have tried looking @ several other similar questions this this , this cannot seem work.

this plugin definition:

(function ($) {     $.fn.switcherbutton = function (options) {         // set default options         var settings = $.extend({},$.fn.switcherbutton.defaults, options);          this.click(function () {             $.fn.switcherbutton.switched = !$.fn.switcherbutton.switched;             settings.onswitch.call($.fn.switcherbutton.switched);         });         return this;     };     // plugin defaults – added property on our plugin function.     $.fn.switcherbutton.defaults = {         onswitch: function() {}     };     $.fn.switcherbutton.switched = false; }(jquery)); 

html:

<a id="switchtest" href="#">switch</a> 

plugin initialization:

$("#switchtest").switcherbutton({     onswitch: function(switched){         if(typeof switched === "undefined")             alert("callback param = undefined");         else             if(switched)                 alert("callback param = true");             else                 alert("callback param = false");     } }); 

i have created jsfiddle of problem here.

change settings.onswitch.call($.fn.switcherbutton.switched) settings.onswitch($.fn.switcherbutton.switched)

call used set , not actual argument function


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -