The difference is that using the first method, you're directly setting a property of the widget object, for example, setting the value
.
In the second example however, you're using the setter provided by dijit/_WidgetBase
, which in turn calls a _set
function, for the value
property it would be _setValueAttr()
. Widgets can extend these setters with custom functionality that will happen when using that setter. For example it can take the necessary steps to display the value as well.
If we, for example pick a dijit/form/Select widget and look at the code of _setValueAttr()
, we notice that it calls some extra functions like:
domAttr.set(this.valueNode, "value", this.get("value"));
this._refreshState(); // to update this.state
This functionality is only called when using dijit.byId("link_id").set("value", "myValue");
, and that's the reason why your value is only displayed in this case. When you're directly setting the property, you're "short-circuiting" this functionality.
TL;DR: Always use the setter function when using Dojo widgets.