ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻝﻭﮊﺎﻣ


فهرست مطالب

    نمایش فهرست مطالب


ﺎﻫ ﻝﻭﮊﺎﻣ

.ﺪﯿﻨﮐ ﻢﯿﺴﻘﺗ ﻪﻧﺎﮔﺍﺪﺟ ﯼﺎﻫ ﻞﯾﺎﻓ ﻪﺑ ﺍﺭ ﺩﻮﺧ ﺪﮐ ﻪﮐ ﺪﻨﻫﺩ ﯽﻣ ﺍﺭ ﻥﺎﮑﻣﺍ ﻦﯾﺍ ﺎﻤﺷ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ

.ﺪﻨﮐ ﯽﻣ ﺮﺗ ﻥﺎﺳﺁ ﺍﺭ ﻪﯾﺎﭘ ﺪﮐ ﮏﯾ ﻆﻔﺣ ﺭﺎﮐ ﻦﯾﺍ

.ﺪﻧﻮﺷ ﯽﻣ ﺩﺭﺍﻭ 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 ﻞﮑﺗﻭﺮﭘ ﻖﯾﺮﻃ ﺯﺍ ﻩﺪﺷ ﺯﺎﺑ ﺏﻭ ﻪﺤﻔﺻ


تمامی حقوق محفوظ است. © BasicIT.org • 2023-2024