I’m reading about the jQuery $.fn namespace, and in order to understand what I’m reading, I would like an example of a complete command if no shortcuts were taken.
For instance,
$('p').click(function() {
console.log('click');
});
Could this be rewritten with .fn in it somewhere? What would be the exhaustive syntax?
jQuery('p',document).fn.click(function() {
window.console.log('click');
});
jQuery.fnis an alias forjQuery.prototype; it’s the standard Javascript prototype mechanism.Actual jQuery objects (instances) do not have an
fnproperty.You need to call the functions such that the
thiskeyword is the object you’re invoking them on, usingcallorapply.For example: