If I write something like this:
var img = $(new Image()).attr('src', image.src);
How can I check later if img var is an image and not something else ?
If I write something like this:
var img = $(new Image()).attr('src', image.src);
How can I check later if img var is an image and not something else ?
img.filter('img')
If this returns something then it is an image.
if ( img.is('img') ){
}
for safety I may be tempted to wrap the var in jQuery again just incase you may have changed the img to a dom node or something else...
if ( $(img).is('img') ){
}
You should avoid explicit type checking.
Use polymorphism to select what has to be done with images, and what has to be done with other objects.
var img = $(new Image())(...);
img.process = function(){ ... do whatever images need ... };
objs.push( img );
var txt = new Text();
txt.process = function(){ .. do text processing, spellcheck, ... };
objs.push( txt );
...
objs.each( o ) { o.process(); }