> For the complete documentation index, see [llms.txt](https://javascriptuse.gitbook.io/advanced/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://javascriptuse.gitbook.io/advanced/requirejs-defining-function.md).

# RequireJS - Defining Function (cách sử dụng require rất lạ) (ok)

Hàm define () có thể được sử dụng để tải các mô-đun (mô-đun có thể là một đối tượng, hàm, lớp hoặc một mã được thực thi sau khi tải một mô-đun). Bạn có thể tải các phiên bản khác nhau của cùng một mô-đun trong cùng một trang. Các phiên bản khác nhau có thể được phân tích theo cùng một thứ tự, ngay cả khi chúng được tải theo một thứ tự khác.

```
define(['module1', 'module2'], function(module1, module2) {
  //define the module value by returning a value
  return function() {};
});
```

![](/files/-MTA57-8-ekDA6YubpCb)

C:\xampp\htdocs\php\index.html

```
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script data-main = "libs/main" src = "libs/require.js"></script>
</head>
<body>
	<h1> RequireJS Sample Page </h1>
  <div id="content" class="navigation">
  	Lorem ipsum dolor sit amet consectetur adipisicing elit. Molestias, ut.
  </div>
</body>
</html>
```

C:\xampp\htdocs\php\libs\main.js

```
define(function (require) {
   var myteam = require("./team");
   var mylogger = require("./player");
   console.log("Player Name : " + myteam.player);
   mylogger.myfunc();
});
```

C:\xampp\htdocs\php\libs\team.js

```
define({
  player: "Lionel",
  team: "VietNam"
});
```

C:\xampp\htdocs\php\libs\player.js

```
define(function(require) {
  var myteam = require("./team");
  return {
    myfunc: function() {
      document.write("Name: " + myteam.player + ", Country: " + myteam.team);
    }
  };
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://javascriptuse.gitbook.io/advanced/requirejs-defining-function.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.
