jQuery plugin Private functions inside Vs. Outside the each loop
Posted
by
Pablo
on Stack Overflow
See other posts from Stack Overflow
or by Pablo
Published on 2011-01-07T18:46:00Z
Indexed on
2011/01/07
21:54 UTC
Read the original article
Hit count: 184
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?
© Stack Overflow or respective owner