> For the complete documentation index, see [llms.txt](https://dingyj.gitbook.io/blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dingyj.gitbook.io/blog/sap/untitled/sapui5-sap.ui.define-and-sap.ui.require.md).

# 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**                            | <ul><li>Node.js</li><li>Server Side</li><li>Compact Syntax</li><li>synchronous loading</li></ul> |
| **Asynchronous module definition(AMD)** | <ul><li>Browser</li><li>complicated syntax</li><li>asynchronous loading</li></ul>                |

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

## Function Definition

### [Define](https://sapui5.hana.ondemand.com/#/api/sap.ui/methods/sap.ui.define)

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

![](/files/-LasGzp7xXkDOxR7bo4_)

### [Require](https://sapui5.hana.ondemand.com/#/api/sap.ui/methods/sap.ui.require)

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

![](/files/-LasH9yJOVjfA65pEFkv)

## Example

You can check this video for detail.

{% embed url="<https://www.youtube.com/watch?v=Yls62sVnins>" %}

{% embed url="<https://gist.github.com/04baf1dcb8fd2312a78fb60a0fe1afa5#file-definerequire-html>" %}

{% embed url="<https://gist.github.com/b4941202bf39c0843bb203ff8074e58c#file-somemodule-js>" %}

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

![](/files/-LasMD9jKvl2JEnFWc8G)
