I understand how to define functions like this:
function myfunc(x,y,z) {
alert("Just an example " + x + y + z)
}
But not this:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
(function ($) {
$.fn.idle = function (x, y, z) {
alert("Just an example " + x + y + z)
}(jQuery));
</script>
The above is a part of a library I'm using, but I simply can't understand the $.fn.idle
bit.
What is it doing? It's defining a function called 'idle', somehow, but what about the $.fn
? And what about the (function ($) {
part? Again, I understand $(document).ready(function() {
but (function ($) {
is completely alien. Is it a short hand?
And what is the significance of the (jQuery));
at the bottom?