Why in jQuery core.js isn't extend defined as like this:
jQuery.extend = jQuery.fn.extend = function() {
...
}
and not as a prototype like:
jQuery.prototype.extend = jQuery.fn.prototype.extend = function() {
...
}
Presumably with the former, objects created from jQuery will not have the extend function.
Because jQuery.fn === jQuery.prototype
It is defined on the prototype. jQuery just decided it would be "cute" to alias the prototype to .fn
Which is why
$().extend({
"lulz": "baz"
}, {
"more-lulz": "no wai"
})["more-lulz"] === "no wai"; // true
Well, because fn is nothing than a shortcut to the prototype property :
console.log($.prototype === $.fn);
Maybe John Resig got bored of typing prototype for every method and set up a nice alias fn (which is indeed shorter and in my opinion more suggestive).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With