I’d like to write a plugin that can be used in the following manner:
var img = $('#someImage').Image();
or perhaps:
var img = $.Image({id: 'someImage', src: '/...'});
and then be able to do image-related functions:
img.highlight();
img.showAlter();
et cetera. However, I don’t want to do:
$.fn.highlight = function() {}
since that would apply to all jQuery objects and i want my method to apply only to those objects I’ve called .Image() on.
is what I’m asking for possible? how?
You’d need to place your
Imagefunction on the prototype (fn), but then have theImageplugin assign thehighlightandshowAfterfunctions to that specific jQuery object on which.Image()is called.EDIT:
To clarify,
thisin theImagefunction is a reference to the jQuery object against whichImage()was invoked.thisdoes not reference theImagefunction in any way.Example: http://jsfiddle.net/saYLm/