Thursday, April 21, 2011

jQuery plugin authoring internal methods

I was writing a jQuery plugin for the first time and the documentation didn't explain well how to properly implement internal methods to your plugin, verses external methods available to the caller which were documented. This is what I got working:

(Sorry for the image, I couldn't find a nice way to style code in Blogger)

Notice in the "return this.each" block, after "var $this = $(this);" a variable is defined as a function. This function is available in the main block as shown by "console.log(fooBar());".

Simple, but I searched around for a bit and didn't fine much. Maybe I have the terminology wrong.

No comments:

Share on Twitter