简体   繁体   中英

Dojo require/define - How to know which function and property belongs to which module?

I have been trying to understand someone else's code, but I am having a difficult time. One of the main reasons is that I keep seeing functions and properties that seem to be part of loaded modules, but they don't seem to have any identifiers with them. One of them is the postCreate function which seems to be loaded with dijit/_WidgetBase. In this particular code it is used as

postCreate: function () {
    // Some code
}

To me it would make more sense by using as:

_WidgetBase.postCreate: function () {
    // Some code
}

Now how am I supposed to know postCreate() belonged to dijit/_WidgetBase without Googling all functions in the code?

Thanks

Had you guys created the proper documentation along the development you wouldn't have to ask these questions ;)

I don't think it's possible what you trying to achieve, the only viable option is to traverse and deconstruct the code as @tik27 is suggesting.

Recommended read would be: https://dojotoolkit.org/reference-guide/1.10/dojo/_base/declare.html

This is basic dojo knowledge you need to gain. After a while you will be used to the available mixins and the method they contain.
Basically, the principle is always the same:

  • Look at which module are in the declare()
  • Open each files corresponding to each declared module
  • Search the method in it.
  • You you do not find it in any of these: repeat the same process with the declare list of all modules you just opened... and so on...

What I usually do it to add a console.log on top of every method of my mixins and classes. The log contains the class path and the method name, so while debugging the code, I can see the "path" and from where it comes... (for instance: console.log('my/new/component/Class::postCreate') ).
But this wont help you with inner Dojo method. You have to know them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM