UI5
For example, I need to messagetoast a message in the controller's Onshowhello to display it on the UI,
I need to define my own controller first, the controller extend from the UI5 standard controller module, the path is Sap/ui/core/mvc/controller, In order to invoke Messagetoast's Show method, you must first get the Messagetoast instance. So UI5 uses Sap.ui.define to load the two dependent module, and after the load is done, it invokes the callback function passed by the application developer, and the contents of the two module loaded are passed into the callback function as two input parameters.
UI5 All module is managed by the module in Jquery.sap.global.js.
For more details please see my former colleague of Sap Wu Ji blog SAPUI5 walkthrough step 6–modules, Dive in–how does modules work?
There is, of course, sap.ui.require this concise usage. An example of the use of a UI5 framework:
Nodejs
Logic and UI5 are similar, assuming that I want to use the QueryString module, just use the NODEJS standard require function to introduce it:
This module can then be used in the application code to expose a method through Module.exports:
Require calls the Self.require in Internal/module.js:
Then the module._load:
Nodejs also has Module unified manager similar to UI5: Module._cache. Each time the module is loaded, first check from this manager if the module is already loaded. Only when the module does not exist in the manager will it actually load, new a module object, maintain the good attributes and then save the module manager.
A loaded module is a collection of function:
To get more original Jerry's technical articles, please follow the public number "Wang Zixi" or scan the QR code below:
Sap.ui.require in SAP UI5 and require in Nodejs