Today I stumbled upon this:
jQuery(document).ready(function($$){
console.log($$);
});
Apparently, $$ is considered as the jQuery object itself. Usually to do such a thing, we need to pass the jQuery variable:
(function($$){
console.log($$);
}(jQuery))
But in case of ready function how does it know $$ is the jQuery object? I think jquery defines the ready function under the hood in a way that passes it's first parameter as jQuery.
This is described in the docs.
In this situation:
jQuery(document).ready(function($$){
console.log($$);
});
window.jQuery has jQuery assigned to itjQuery(document) references that global identifierThis functionality doesn't have much use unless you're using jQuery.noConflict, but for another example of something similar:
theLibrary().ready(function($$){
console.log($$.libraryProp);
});
<script>
// library example
window.theLibrary = Object.assign(
// the library is both a function
() => ({
ready: (callback) => {
callback(window.theLibrary);
}
}),
// and an object with properties
{
libraryProp: 'libraryProp'
}
);
</script>