# 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
```

![](https://3536919124-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaJGzuTd3rg88xS__Wx%2F-LasDzEwaorTcqjwH7C0%2F-LasGzp7xXkDOxR7bo4_%2Fimage.png?alt=media\&token=4883c8cb-a9d8-4066-8f3d-aaace827b920)

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

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

![](https://3536919124-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaJGzuTd3rg88xS__Wx%2F-LasDzEwaorTcqjwH7C0%2F-LasH9yJOVjfA65pEFkv%2Fimage.png?alt=media\&token=97004749-1b4e-4a0a-a317-35353792b3a0)

## 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.

![](https://3536919124-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaJGzuTd3rg88xS__Wx%2F-LasDzEwaorTcqjwH7C0%2F-LasMD9jKvl2JEnFWc8G%2Fimage.png?alt=media\&token=fa2dca2a-e29a-4669-8bcd-daa7754c2435)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dingyj.gitbook.io/blog/sap/untitled/sapui5-sap.ui.define-and-sap.ui.require.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
