I am learning javascript sample from this page,
http://nofunc.org/AJAX_Star_Rating
my questions are (1),
for function function XY(e,v), it has two input parameters e and v, but it is called with only one parameter x=XY(e), how does it work?
question (2), I am confused about what this function XY is doing below, especially confused about the grammar {'X':e.pageX,'Y':e.pageY} and v?o[v]:o, could anyone explain what do they mean please?
var o=agent('msie')?{'X':event.clientX+document.documentElement.scrollLeft,'Y':event.clientY+document.documentElement.scrollTop}:{'X':e.pageX,'Y':e.pageY}; return(v?o[v]:o); }
thanks in advance,
George
function XY(e,v)is an event handler. First argument is the event object passed to the function, second is the element affected. The function is called automatically by Javascript when the relevant event is triggered.{'X':e:pageX, 'Y':e:pageY}are just key-value pairs. Essentially, an “array” with identifiers for each element and a value corresponding to that identifier. Strictly speaking, Javascript doesn’t have “arrays”. They’re called objects. The identifiers are called properties.v?o[v]:otranslates toif (v) return o[v]; else return o;Ternary expressions, as they are known, also appear in the last line.if (agent('msie')) var o={'X':event...}; else var o={'X':e.pageX,...};