You’re assigning your function to
$.fn.myFunction, but calling it like
If your function does not operate on the dom, I would suggest assigning it to
$ directly (or not using jQuery at all).
If you are interested in writing a jQuery plugin, remember that you’ll need to call your method on a jQuery object (i.e., something returned by
. . .
Also, inside your function, use
this instead of
$ to reference your variables: updated fiddle
. . . OR, make
myGlobals a property of
myFunction (unless there’s a really good reason not to – it’s best to use as few names as possible in
$.fn): updated fiddle #2