jQuery plugin Private functions inside Vs. Outside the each loop
- by Pablo
What is the difference between including private functions in a jQuery plugin in the examples below:
Outside the loop:
(function( $ ){
var defaults = {};
$.fn.cmFlex = function(opts) {
this.each(function() {
var $this = $(this);
//Element specific options
var o = $.extend({}, defaults, opts);
//Code here
});
function f1(){....
function f3(){....
function f2(){....
};
})( jQuery );
Inside the loop:
(function( $ ){
var defaults = {};
$.fn.cmFlex = function(opts) {
this.each(function() {
var $this = $(this);
//Element specific options
var o = $.extend({}, defaults, opts);
function f1(){....
function f3(){....
function f2(){....
});
};
})( jQuery );
The advantage of including the functions in the loop is that i will be able to access the $this variable as well as the Element specific options from f1() f2() f3(), are there any disadvantages to this?