What is the difference between including private functions in the jQuery plugin in the following examples:
Out of cycle:
(function( $ ){
var defaults = {};
$.fn.cmFlex = function(opts) {
this.each(function() {
var $this = $(this);
var o = $.extend({}, defaults, opts);
});
function f1(){....
function f3(){....
function f2(){....
};
})( jQuery );
Inside the loop:
(function( $ ){
var defaults = {};
$.fn.cmFlex = function(opts) {
this.each(function() {
var $this = $(this);
var o = $.extend({}, defaults, opts);
function f1(){....
function f3(){....
function f2(){....
});
};
})( jQuery );
The advantage of including functions in the loop is that I get access to the $ this variable, as well as to certain parameters of the element from f1 () f2 () f3 (), are there any disadvantages?
source
share