javascript - DOJO: Overriding a method in Dijit widget -


i need pass arguments widget watch method can used in callback function

current code:

require(["dijit/form/numbertextbox"], function (numbertextbox) {     var txt = new numbertextbox({}, "text10");     txt.watch("value", function (name, oldvalue, value) {      }); }); 

desired code:

require(["dijit/form/numbertextbox"], function (numbertextbox) {     var txt = new numbertextbox({}, "text10");     txt.watch("value", function (name, oldvalue, value, panelid) {         alert(panelid);     },panelid); }); 

need induct panelid in watch function. have searched docs seems cannot pass arguments watch function. is there way override watch method , make accept arguments?

you can wrap callback function in closure keeps local reference panelid variable. assumes panelid not meant change across invocations of watch function.

require(["dijit/form/numbertextbox"], function (numbertextbox) {     var txt = new numbertextbox({}, "text10");     var panelid = ... // comes somewhere      (function (panelid) {         txt.watch("value", function (name, oldvalue, value) {             alert(panelid);         });     })(panelid); }); 

the callback function watch function creates closure, can simplify above code just:

require(["dijit/form/numbertextbox"], function (numbertextbox) {     var txt = new numbertextbox({}, "text10");     var panelid = ... // comes somewhere      txt.watch("value", function (name, oldvalue, value) {         alert(panelid);     }); }); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -