I have a dojo module and I want to use the this keyword but there is a problem .
is required ("dojo / _base / declare", "dojo / _base / lang", "dojo / query", "dojo / on", "dojo / dom", " Dojo / nodlist-transverse "], function (declare, lang, query, on, dom, nls) {var mainWidget = declare (null, {constructor: function () {this.onItemClicked = lang.hitch (this, this. OnItemClicked); (Dom.byId ("myList"), "toggle: click", this.onItemClicked);}, onItemClicked: function (event) {dom.byId ("result"). InnerHTML = this._calculate (); Dom.byId ("result"). InnerHTML = query (this) .Parent ('li');}, _calculate: function () {10 * 10;}}); var wg = new mainWidget (); });
I onItemClicked in event handler . I want to use a method called _ calculation which is outside the event handler and I use the query (this) object
I want to use this ._calculate (), but return the query (this) element, but do not return.
This link is
So if I understand well, then This should reference both code (for the
_calculate ()
function) and click on the DOM node (for the query ()
function)?
This is actually a big bad practice you want to refer to two objects using a reference, not only this is bad, it makes your code unreadable
Dom.byId ("Result"), just like this: Just click the element to get the element to use the target
property of the event handler. Internal HTML + = query (event.target). Parent ('li');
But do not forget that you are overriding your #result
HTML because you are using:
dom ById ("Result"). InnerHTML = ...;
If you want to add it next to the calculation value ( 100
), then use the + =
operator.
Small note : You can use the this
context for both widget and target element by adding both objects, but like I Said, it is not like to have a good idea.
Comments
Post a Comment