javascript - dojo - lang.hitch for widget function -
i have custom widget , curious if can use lang.hitch
in particular way. here scenario:
say have custom widget contains button
. button
needs function attached onclick
event. so, in template have:
<button data-dojo-type="dijit/form/button" data-dojo-attach-event="onclick : _onbuttonclick" />
then, in widget .js
file have:
_onbuttonclick : function(evt) { //do here needs scope of widget (this) }
i know remove data-dojo-attach-event
template , use dojo.connect
lang.hitch
in postcreate
, i'm wondering if convert _onbuttonclick
function this:
_onbuttonclick : lang.hitch(this, function(evt) { //do here needs scope of widget (this) })
data-dojo-attach-event
automatically makes scope of this
parent widget.
i'm not 100% sure, don't think context of this
in snippet declare([/deps/,{
_onbuttonclick : lang.hitch(this, function(evt) { //do here needs scope of widget (this) }) });
is want to. believe when function bound scope declare function executed in, rather instance of widget.
Comments
Post a Comment