javascript - is event a global variable that is accessible everywhere inside the callback chain? -


i playing around event listeners dom , javascript , did notice this:

function chained(msg) {     console.log(msg, event); }  function onclick() {     chained('the body clicked'); }  document.body.addeventlistener('click', onclick); 

now funny thing...this output:

"the body clicked, (mouseevent)"

then ask, why? how passes event object without sending on chained call?

function chained(msg) {     console.log(msg, namedeventobj); //throw error namedeventobj not defined }  function onclick(namedeventobj) {     console.log(event); //outputs (mouseevent);     console.log(nameeventobj); //outputs (mouseevent);     chained('the body clicked'); }  document.body.addeventlistener('click', onclick); 

even if declare event obj passed on onclick function namedeventobj available onclick not chained function...i got , makes sense me...but not event variable available chained function.

anyone know why behaves this?

the thing can think of event in fact window.event , makes available when event dispatches , event...but mean element event information if called @ same time event when triggers?

i using chrome 11.0.x

one can access current event through window.event. using event implicitly accessing window.event.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -