javascript - Dojo.hitch immediately-called: Confirming my suspicions -
this quick one. understand, dojo.hitch()
function useful giving function callback called in namespace need (the first argument). however, i've seen number of calling syntaxes following:
dojo.hitch(iamanamespace, iamanamespace.dosomething)();
the part weirds me out 2 parentheses @ end. they're apparently not creating function later - they're calling right now. obvious thought shortened to:
iamanamespace.dosomething();
i sort of doing replacement absent-mindedly, thinking result of being over-careful this
references, found able locate few instances of in "dojox" modules, , 1 inside of dojo/_base/lang did change namespace context, still have used ".call()
".
can confirm who's used dojo while situation, if any, might demand use of hitch called immediately, opposed doing normal, old-fashioned way?
i haven't used dojo, looking @ the source can tell you're right. when know arguments, should shorten call.
there might 1 reason use hitch
though: if want allow both functions , method names might shorter immediately-invoke hitched function write like
if (typeof fn == "string") fn = (context || global)[fn]; if (typof fn == "function") fn.call(context); else throw "not function";
Comments
Post a Comment