Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142239

Why is parameter in callback function optional? [duplicate]

$
0
0

If you omit a parameter to a callback function, it still works. For example,

var callback1 = function() {
    $("span").prepend("Callback 1: " +  event.pageX + "" + event.pageY + "<br>");
};
$("div").click(callback1);

works when the event parameter is not passed. It seems equivalent to:

var callback2 = function(event) {
    $("span").prepend("Callback 2: " +  event.pageX + "" + event.pageY + "<br>");
};
$("div").click(callback2);

with the parameter passed as I feel it should be.

Working JSFiddle of this here.


I found this JS phenomenon peculiar. Why does it work?


Viewing all articles
Browse latest Browse all 142239

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>