Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling function of $.fn.function

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.

like image 582
rakeden Avatar asked Mar 27 '13 11:03

rakeden


People also ask

What is the function of Fn?

Keys with an Fn key or F Lock provide two sets of commands for many keys. This includes the top row of standard function keys (F1–F12). Standard commands are labeled on the front of the keys (such as F3). Alternate commands are labeled on top of the keys (such as Redo).

What is F1 F2 F3 f4 f5 f6 f7 f8 f9 f10 f11 F12?

The function keys or F-keys on a computer keyboard, labeled F1 through F12, are keys that have a special function defined by the operating system, or by a currently running program. They may be combined with the Alt or Ctrl keys.

How do I activate the Fn function?

Press fn and the left shift key at the same time to enable fn (function) mode.

How do I use Fn key without pressing Fn?

Method 1. Toggle the Fn Lock key All you have to do is look on your keyboard and search for any key with a padlock symbol on it. Once you've located this key, press the Fn key and the Fn Lock key at the same time. Now, you'll be able to use your Fn keys without having to press the Fn key to perform functions.


2 Answers

foo 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 recommend creating globals, you should probably attach the function to some other object):

$.fn.slides = function(args){
   function foo(args){ }
   window.foo = foo;
}
like image 158
Quentin Avatar answered Sep 20 '22 22:09

Quentin


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);
}
like image 44
Daniel Imms Avatar answered Sep 22 '22 22:09

Daniel Imms