.ﺪﯿﻨﮐ ﻢﯿﺴﻘﺗ ﻪﻧﺎﮔﺍﺪﺟ ﯼﺎﻫ ﻞﯾﺎﻓ ﻪﺑ ﺍﺭ ﺩﻮﺧ ﺪﮐ ﻪﮐ ﺪﻨﻫﺩ ﯽﻣ ﺍﺭ ﻥﺎﮑﻣﺍ ﻦﯾﺍ ﺎﻤﺷ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
.ﺪﻨﮐ ﯽﻣ ﺮﺗ ﻥﺎﺳﺁ ﺍﺭ ﻪﯾﺎﭘ ﺪﮐ ﮏﯾ ﻆﻔﺣ ﺭﺎﮐ ﻦﯾﺍ
.ﺪﻧﻮﺷ ﯽﻣ ﺩﺭﺍﻭ import
ﺕﺭﺎﺒﻋ ﺎﺑ ﯽﺟﺭﺎﺧ ﯼﺎﻫ ﻞﯾﺎﻓ ﺯﺍ ﺎﻫ ﻝ
.ﺪﻨﺘﺴﻫ ﯽﮑﺘﻣ <script> ﮓﺗ ﺭﺩ type="module"
ﻪﺑ ﻦﯿﻨﭽﻤﻫ ﺎ
<script type="module">
import message from "./message.js";
</script>
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Modules</h1>
<p id="demo"></p>
<script type="module">
import message from "./message.js";
document.getElementById("demo").innerHTML = message();
</script>
</body>
</html>
.ﺩﺮﮐ ﻩﺮﯿﺧﺫ ﯽﺟﺭﺎﺧ ﻞﯾﺎﻓ ﺮﻫ ﺭﺩ ﻥﺍﻮﺗ ﯽﻣ ﺍﺭ ﺮﯿﻐﺘﻣ ﺎﯾ ﻊﺑﺍﻮﺗ ﯼﺍﺭﺍﺩ ﯼﺎﻫ ﻝﻭﮊﺎﻣ
.ﺽﺮﻓﺶﯿﭘ ﺕﺍﺭﺩﺎﺻ ﻭ ﻡﺎﻧ ﺎﺑ ﺕﺍﺭﺩﺎﺻ :ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﺕﺍﺭﺩﺎﺻ ﻉﻮﻧ ﻭﺩ
ﻭ ،ﻢﯿﻨﮐ ﺩﺎﺠﯾﺍ person.js
ﻡﺎﻧ ﻪﺑ ﯽﻠﯾﺎﻓ ﺪﯿﻫﺩ ﻩﺯﺎﺟﺍ
.ﻦﯿﯾﺎﭘ ﺭﺩ ﻥﺎﻣﺯ ﮏﯾ ﺭﺩ ﻪﻤﻫ ﺎﯾ ،ﻪﻧﺎﮔﺍﺪﺟ ﺕﺭﻮﺻ ﻪﺑ ﻂﺧ ﺭﺩ .ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ ﺵﻭﺭ ﻭﺩ ﻪﺑ ﺍﺭ ﻩﺪﺷ ﯼﺭﺍﺬﮕ
person.js
export const name = "Jesse";
export const age = 40;
person.js
const name = "Jesse";
const age = 40;
export {name, age};
ﻭ ﻢﯿﻨﮐ ﺩﺎﺠﯾﺍ message.js
ﻡﺎﻧ ﻪﺑ ﯼﺮﮕﯾﺩ ﻞﯾﺎﻓ ﺪﯿﻫﺩ ﻩﺯﺎﺟﺍ
.ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻞﯾﺎﻓ ﮏﯾ ﺭﺩ ﺽﺮﻓ ﺶﯿﭘ ﺕﺍﺭﺩﺎﺻ ﮏﯾ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﻂﻘﻓ ﺎﻤﺷ
message.js
const message = () => {
const name = "Jesse";
const age = 40;
return name + ' is ' + age + 'years old.';
};
export default message;
ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﺎﻬﻧﺁ ﻡﺎﻧ ﺎﯾﺁ ﻪﮑﻨﯾﺍ ﺱﺎﺳﺍ ﺮﺑ ،ﺪﯿﻨﮐ ﺩﺭﺍﻭ ﻞﯾﺎﻓ ﮏﯾ ﺭﺩ ﺵﻭﺭ ﻭﺩ ﻪﺑ ﺍﺭ ﺎﻫ ﻝﻭﮊﺎﻣ ﺪﯿﻧﺍ
.ﺖﺴﯿﻧ ﺽﺮﻓ ﺶﯿﭘ ﺕﺍﺭﺩﺎﺻ .ﺩﻮﺷ ﯽﻣ ﻪﺘﺧﺎﺳ ﯼﺮﻓﺮﻓ ﯼﺎﻫ ﺲﯾﺮﺑ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﻩﺪﺷ ﯼﺭﺍﺬﮕﻣﺎﻧ ﺕﺍﺭﺩﺎﺻ
:ﺪﯿﻨﮐ ﺩﺭﺍﻭ person.js ﻞﯾﺎﻓ ﺯﺍ ﺍﺭ ﻡﺎﻧ ﺎﺑ ﺕﺍﺭﺩﺎﺻ
import { name, age } from "./person.js";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Modules</h1>
<p id="demo"></p>
<script type="module">
import { name, age } from "./person.js";
let text = "My name is " + name + ", I am " + age + ".";
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﺩﺭﺍﻭ message.js ﻞﯾﺎﻓ ﺯﺍ ﺍﺭ ﺽﺮﻓ ﺶﯿﭘ ﺕﺍﺭﺩﺎﺻ ﮏﯾ
import message from "./message.js";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Modules</h1>
<p id="demo"></p>
<script type="module">
import message from "./message.js";
document.getElementById("demo").innerHTML = message();
</script>
</body>
</html>
.ﺪﻨﻨﮐ ﯽﻣ ﺭﺎﮐ HTTP (ﯼﺎﻫ)ﻞﮑﺗﻭﺮﭘ ﺎﺑ ﻂﻘﻓ ﺎﻫ ﻝﻭﮊﺎﻣ
.ﺪﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ import/export ﺯﺍ ﺪﻧﺍﻮﺗ ﯽﻤﻧ //:file ﻞﮑﺗﻭﺮﭘ ﻖﯾﺮﻃ ﺯﺍ ﻩﺪﺷ ﺯﺎﺑ ﺏﻭ ﻪﺤﻔﺻ