I recently saw this code in another post ( jQuery Set cursor position in text area )
new function($) {
$.fn.setCursorPosition = function(pos) {
}
} (jQuery);
For too long, trying to figure out what it is doing, I finally realized that it just creates a new function with the $ parameter, and then calls it using jQuery as the parameter value.
So in fact, he just does this:
jQuery.fn.setCursorPosition = function(pos) {
}
What is the reason for the original, more confusing version?
source
share