jQuery.extend() and jQuery.fn.extend() are the same… Right?
This question already has an answer here:
$.extend
simply extends an object
var obj1 = {'name' : 'Progo'};
var obj2 = {'value' : 'stack overflow'};
$.extend(obj1, obj2);
// obj1 is now {'name' : 'Progo', 'value' : 'stack overflow'}
FIDDLE
jQuery.fn.extend
extends the jQuery prototype
jQuery.fn.extend({
turn_red: function() {
return this.each(function() {
this.style.color = 'red'
});
}
});
// gives you
$('elements').turn_red(); // sets color to red
FIDDLE
The key difference is here:
// extend jQuery itself if only one argument is passed
if ( length === i ) {
target = this;
--i;
}
this
will be different depending on whether $.extend
or $.fn.extend
was called.