I mentioned earlier that the arguments to a widget that can be passed with attributes are limited to those that are already fields on the object. What I didn't realize then, and which has caused me a great deal of trouble previously, is that the parsing of those arguments depends on what the default value is!
Say that we have a widget like this:
dojo.declare("swadesh.languagePicker", [ dijit._Widget, dijit._Templated ], {
templatePath: dojo.moduleUrl('swadesh', 'templates/languagePicker.html'),
languages: [],
loadDelay: 10,
title: 'language',
hook: null,
postConstruct: function() {
console.log("Title: " + this.title + " hook: " + this.hook
+ " languages: " + this.languages.toSource() + " delay: " + this.loadDelay);
}
...
It allows four arguments to be passed with a dojoType style declaration, but they'll be handled very differently. The languages parameter is parsed as a list, so you can say '[1,2]' and it will be an actual list. The loadDelay is parsed as a number, so anything that doesn't parse as a number will become NaN. The title is parsed as a string, so no further evaluation is done. The hook is parsed as raw JavaScript and evaluated! Let's see this happen:
loadDelay="13.3" title="a.b(1+3)"
hook="'swadesh'.substr(3,3)">
No comments:
Post a Comment