ﻡﺎﮕﻤﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ


فهرست مطالب

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

"ﺪﻨﮐ ﯽﻣ ﺮﺗ ﻥﺎﺳﺁ ﺍﺭ ﺎﻫ ﻩﺪﻋﻭ ﻦﺘﺷﻮﻧ ﺭﺎﻈﺘﻧﺍ ﻭ ﯼﺯﺎﺳ ﻡﺎﮕﻤﻫﺎﻧ"

async ﮏﯾ ﻊﺑﺎﺗ ﮏﯾ ﺩﻮﺷ ﯽﻣ ﺚﻋﺎﺑ Promise ﺪﻧﺍﺩﺮﮔﺮﺑ

wait ﮏﯾ ﺮﻈﺘﻨﻣ ﻊﺑﺎﺗ ﮏﯾ ﺩﻮﺷ ﯽﻣ ﺚﻋﺎﺑ Promise ﺪﺷﺎﺑ

ﻡﺎﮕﻤﻫﺎﻧ ﻮﺤﻧ

:ﺪﻧﺍﺩﺮﮔﺮﺑ ﺍﺭ ﻩﺪﻋﻭ ﮏﯾ ﻊﺑﺎﺗ ﻪﮐ ﺩﻮﺷ ﯽﻣ ﺚﻋﺎﺑ ﻊﺑﺎﺗ ﮏﯾ ﺯﺍ ﻞﺒﻗ ﻡﺎﮕﻤﻫﺎﻧ<"code class="w

ﻝﺎﺜﻣ

async function myFunction() {
  return "Hello";
}

:ﻪﮐ ﺖﺴﻫ ﻦﯾﺍ ﻞﺜﻣ

function myFunction() {
  return Promise.resolve("Hello");
}

:ﺖﺳﺍ ﻩﺪﻣﺁ Promise ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻩﻮﺤﻧ ﺎﺠﻨﯾﺍ ﺭﺩ

myFunction().then(
  function(value) { /* code if successful */ },
  function(error) { /* code if some error */ }
);

ﻝﺎﺜﻣ

async function myFunction() {
  return "Hello";
}
myFunction().then(
  function(value) {myDisplayer(value);},
  
  function(error) {myDisplayer(error);}
);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript async / await</h2>

<p id="demo"></p>

<script>
function myDisplayer(some) {
  document.getElementById("demo").innerHTML = some;
}

async function myFunction() {return "Hello";}

myFunction().then(
  function(value) {myDisplayer(value);},
  function(error) {myDisplayer(error);}
);</script>

</body>
</html>

:ﺪﯾﺭﺍﺩ ﺍﺭ (ﺎﻄﺧ ﮏﯾ ﻪﻧ ،ﯼﺩﺎﻋ ﺦﺳﺎﭘ ﮏﯾ) ﻝﺎﻣﺮﻧ ﺭﺍﺪﻘﻣ ﮏﯾ ﺭﺎﻈﺘﻧﺍ ﺎﻤﺷ ﺍﺮﯾﺯ ،ﺮﺗ ﻩﺩﺎﺳ ﺎﯾ

ﻝﺎﺜﻣ

async function myFunction() {
  return "Hello";
}
myFunction().then(
  function(value) {myDisplayer(value);}
);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript async / await</h2>

<p id="demo"></p>

<script>
function myDisplayer(some) {
  document.getElementById("demo").innerHTML = some;
}

async function myFunction() {return "Hello";}

myFunction().then(
  function(value) {myDisplayer(value);}
);
</script>

</body>
</html>

ﻮﺤﻧ ﺮﻈﺘﻨﻣ

ﮏﯾ ﻞﺧﺍﺩ ﺭﺩ ﺪﻧﺍﻮﺗ ﯽﻣ ﻂﻘﻓ wait ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ

ﺪﻨﮐ ﯽﻣ ﻒﻗﻮﺘﻣ ﺍﺭ ﺩﺮﮑﻠﻤﻋ wait ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ

let value = await promise;


ﻝﺎﺜﻣ

.ﻢﯾﺮﯿﮕﺑ ﺩﺎﯾ ﺍﺭ ﻥﺁ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻩﻮﺤﻧ ﻭ ﻢﯾﻭﺮﺑ ﺶﯿﭘ ﻪﺘﺴﻫﺁ ﺪﯿﯾﺎﯿﺑ

ﻪﯾﺎﭘ ﻮﺤﻧ

async function myDisplay() {
  let myPromise = new Promise(function(resolve,  reject) {
    resolve("I love You !!");
  });
  document.getElementById("demo").innerHTML = await myPromise;
}

 myDisplay();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript async / await</h2>

<h1 id="demo"></h1>

<script>
async function myDisplay() {
  let myPromise = new Promise(function(resolve, reject) {
    resolve("I love You !!");
  });
  document.getElementById("demo").innerHTML = await myPromise;
}

myDisplay();
</script>

</body>
</html>

.ﺪﻧﺍ ﻩﺪﺷ ﻒﯾﺮﻌﺗ ﺶﯿﭘ ﺯﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻂﺳﻮﺗ (ﻥﺩﺮﮐ ﺩﺭ ﻭ ﻥﺩﺮﮐ ﻞﺣ) ﻥﺎﻣﻮﮔﺭﺁ ﻭﺩ

.ﻢﯿﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺍﺭ ﺎﻬﻧﺁ ﺯﺍ ﯽﮑﯾ ،ﺪﺷ ﻩﺩﺎﻣﺁ ﻩﺪﻨﻨﮐ ﺍﺮﺟﺍ ﻊﺑﺎﺗ ﻪﮐ ﯽﻧﺎﻣﺯ ﺎﻣﺍ ،ﻢﯿﻨﮐ ﯽﻤﻧ ﺩﺎﺠ

.ﻢﯾﺭﺍﺪﻧ ﺯﺎﯿﻧ ﺩﺭ ﻊﺑﺎﺗ ﻪﺑ ﺎﻣ ﺐﻠﻏﺍ

ﺩﺭ ﻥﻭﺪﺑ ﻝﺎﺜﻣ

async function myDisplay() {
  let myPromise = new Promise(function(resolve) {
    resolve("I love You !!");
  });
  document.getElementById("demo").innerHTML = await myPromise;
}

 myDisplay();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript async / await</h2>

<h1 id="demo"></h1>

<script>
async function myDisplay() {
  let myPromise = new Promise(function(resolve) {
    resolve("I love You !!");
  });
  document.getElementById("demo").innerHTML = await myPromise;
}

myDisplay();
</script>

</body>
</html>

ﯽﻧﺎﻣﺯ ﺖﻠﻬﻣ ﺭﺎﻈﺘﻧﺍ ﺭﺩ

async function myDisplay() {
  let myPromise = new Promise(function(resolve) {
    setTimeout(function() {resolve("I love You !!");}, 3000);
  });
  document.getElementById("demo").innerHTML = await myPromise;
}

 myDisplay();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript async / await</h2>

<p>Wait 3 seconds (3000 milliseconds) for this page to change.</p>

<h1 id="demo"></h1>

<script>
async function myDisplay() {
  let myPromise = new Promise(function(resolve) {
    setTimeout(function() {resolve("I love You !!");}, 3000);
  });
  document.getElementById("demo").innerHTML = await myPromise;
}

myDisplay();
</script>

</body>
</html>

ﻞﯾﺎﻓ ﮏﯾ ﺭﺎﻈﺘﻧﺍ ﺭﺩ

async function getFile() {
  let myPromise = new Promise(function(resolve) {
    let req = new XMLHttpRequest();
    req.open('GET', "mycar.html");
    req.onload = function() {
      if (req.status == 200) {
        resolve(req.response);
      } else {
        resolve("File not Found");
      }
    };
    req.send();
  });
  document.getElementById("demo").innerHTML = await myPromise;
}

getFile();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript async / await</h2>

<p id="demo"></p>

<script>
async function getFile() {
  let myPromise = new Promise(function(resolve) {
    let req = new XMLHttpRequest();
    req.open('GET', "mycar.html");
    req.onload = function() {
      if (req.status == 200) {
        resolve(req.response);
      } else {
        resolve("File not Found");
      }
    };
    req.send();
  });
  document.getElementById("demo").innerHTML = await myPromise;
}

getFile();
</script>

</body>
</html>

ﺮﮔﺭﻭﺮﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ

ECMAScript 2017 ﺩﺮﮐ ﯽﻓﺮﻌﻣ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺪﯿﻠﮐ ﺕﺎﻤﻠﮐ

:ﺪﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ ﻭﺩ ﺮﻫ ﺯﺍ ﻞﻣﺎﮐ ﯽﻧﺎﺒﯿﺘﺸﭘ ﺎﺑ ﺍﺭ ﺮﮔﺭﻭﺮﻣ ﻪﺨﺴﻧ ﻦﯿﻟﻭﺍ ﺮﯾﺯ ﻝﻭﺪﺟ

Chrome 55 Edge 15 Firefox 52 Safari 11 Opera 42
Dec, 2016 Apr, 2017 Mar, 2017 Sep, 2017 Dec, 2016