I am trying to understand the example of Todos in Meteor. There is a piece of code that I cannot understand:
// Returns an event map that handles the "escape" and "return" keys and // "blur" events on a text input (given by selector) and interprets them // as "ok" or "cancel". var okCancelEvents = function (selector, callbacks) { var ok = callbacks.ok || function () {}; var cancel = callbacks.cancel || function () {}; var events = {}; events['keyup '+selector+', keydown '+selector+', focusout '+selector] = function (evt) { if (evt.type === "keydown" && evt.which === 27) { // escape = cancel cancel.call(this, evt); } else if (evt.type === "keyup" && evt.which === 13 || evt.type === "focusout") { // blur/return/enter = ok/submit if non-empty var value = String(evt.target.value || ""); if (value) ok.call(this, value, evt); else cancel.call(this, evt); } }; return events; };
What gives events['keyup '+selector+', keydown '+selector+', focusout '+selector] = function(){} ?
Why do we need to convert the following to a string: String(evt.target.value || "") ?
Should the evt argument of the specified function have .type, .target, and .target.value? What can i transfer to evt?
source share