I'm writing jQuery plugin and got a small problem -- cannot get a variable out of event's handler function. Take a look at my example for understanding:
(function( $ ){
  var methods = {
  init : function( options ) {
   var settings = $.extend( {
    'images': [['1.jpg'],['2.jpg'],['3.jpg']]
    }, options);
    var lastim=2; //just for test
    $.each(settings.images,function(event) {
    console.log(lastim); //Getting 2, Ok!
    img=new Image();
    img.src=settings.thumbPath+'/'+this[0];
    $(img).load(function(event)
            {      
            lastim=5;
            });
    });
    console.log(lastim); //Getting 2, expecting 5
   }};
$.fn.testSlider = function( method ) {
    if ( methods[method] ) {
      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    } else {
      $.error( 'No such method'+method );
    } 
};
})( jQuery );
How to get 5 in lastim variable after each function? Thank you in advance for helping!
 
     
     
    