How can I call a function defined as JQuery plugin option parameter in my Base Script?
Plugin
$.fn.myPlugin = function(){
var config = $.extend({
read:function(){}
})
config.read.call(this);
}
Sample Usage
$("#someElement").myPlugin({
read: function myFunc(){
//some code
}
});
function anotherFunc(){
myFunc();
//here, why I cant call the function myFunc defined as one of my option parameter for Jquery Plugin
}
read:is scoped to the myPlugin init object - you would normally use an anonymous (unnamed) function here as the name is unusable elsewhere (due to its scope):read: function() {.... Use a global function:function myFunc() {..read: myFunc.myfuncfunction?config. This answer might help you to create jquery-plugin-style options: stackoverflow.com/a/6457128/2181514 ->$("#id").myPlugin("read")See also this answer: stackoverflow.com/a/25343333/2181514myPlugin.config.read.call(this)?. Is it correct?$.fn.myPlugin.config.read...but if you have a different config per call to myPlugin then you need to store it on the element itself. See the above links.