The problem is the following. Theres is a function custom jquery function with another function inside, f.e.:
$.fn.slides = function(args){
function foo(args){
}
}
My question is now: How can I call the method foo.
The problem is the following. Theres is a function custom jquery function with another function inside, f.e.:
$.fn.slides = function(args){
function foo(args){
}
}
My question is now: How can I call the method foo.
Share Improve this question asked Mar 27, 2013 at 11:35 rakedenrakeden 1921 silver badge8 bronze badges 1- 2 From outside the plugin? You can't. You'd have to expose the function one way or another. – Felix Kling Commented Mar 27, 2013 at 11:37
2 Answers
Reset to default 5foo
is not a method. It is a local function. There is no way to access it from outside the function in which it is defined unless you modify that function to expose it.
For example (and I do not remend creating globals, you should probably attach the function to some other object):
$.fn.slides = function(args){
function foo(args){ }
window.foo = foo;
}
You can't call it from outside the function, unless you return an object which has foo
attached to it, something like this:
$.fn.slides = function(args){
this.foo = function (args){
}
return this;
}
$('blah').slides(args).foo(args);
Inside the function you can use it as a regular function:
$.fn.slides = function(args) {
function foo(args) {
}
foo(args);
}