SAPUI5 sap.ui.define and sap.ui.require

If you are a beginner of SAPUI5. you may be confused about the difference between sap.ui.define and sap.ui.require.

Simple Conclusion

  • sap.ui.define global namespace for your module and load dependent modules. (Define Module)

  • sap.ui.require load dependent modules without declaring a namespace synchronously. (Call Module)

Why

sap.ui.define and sap.ui .require are the same as in RequireJS. They are both provided to load module.

In javascript, There is no built-in module feature and there are 2 popular concept for modularization.

Concept

Feature

CommonJS

  • Node.js

  • Server Side

  • Compact Syntax

  • synchronous loading

Asynchronous module definition(AMD)

  • Browser

  • complicated syntax

  • asynchronous loading

Because SAPUI5 runs in the browser, sap use the AMD concept.(I doubt that...)

Function Definition

sap.ui.define(sModuleName?, aDependencies?, vFactory, bExport?) : void

sap.ui.require(vDependencies, fnCallback?, fnErrback?) : any|undefined

Example

You can check this video for detail.

If you change the SomeModule's define to Require. It would load the file but you will get error because it's not defined.

Last updated