"ﺩﺮﮐ ﻢﻫﺍﻮﺧ ﻡﺎﻤﺗ ﺍًﺪﻌﺑ!"
.ﺪﻧﻮﺷ ﯽﻣ ﻩﺪﯿﻣﺎﻧ ﻥﺎﻣﺰﻤﻫﺎﻧ ﺪﻧﻮﺷ ﯽﻣ ﺍﺮﺟﺍ ﻊﺑﺍﻮﺗ ﺮﯾﺎﺳ ﺎﺑ ﯼﺯﺍﻮﻣ ﺕﺭﻮﺻ ﻪﺑ ﻪﮐ ﯽﻌ
.ﺖﺳﺍ() setTimeout ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺏﻮﺧ ﻝﺎﺜﻣ ﮏﯾ
.ﺩﻮﺑ ﻩﺩﺎﺳ ﺭﺎﯿﺴﺑ ﻞﺒﻗ ﻞﺼﻓ ﺭﺩ ﻩﺪﺷ ﻩﺩﺎﻔﺘﺳﺍ ﯼﺎﻫ ﻝﺎﺜﻣ
:ﺩﻮﺑ ﺱﺎﻤﺗ ﻪﺑ ﺦﺳﺎﭘ ﻊﺑﺍﻮﺗ ﻮﺤﻧ ﻥﺩﺍﺩ ﻥﺎﺸﻧ ﺎﻫ ﻝﺎﺜﻣ ﺯﺍ ﻑﺪﻫ
function myDisplayer(something) {
document.getElementById("demo").innerHTML
= something;
}
function myCalculator(num1, num2, myCallback) {
let sum = num1 + num2;
myCallback(sum);
}
myCalculator(5, 5, myDisplayer);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>
<h2>Callback Functions</h2>
<p>The result of the calculation is:</p>
<p id="demo"></p>
<script>
function myDisplayer(something) {
document.getElementById("demo").innerHTML = something;
}
function myCalculator(num1, num2, myCallback) {
let sum = num1 + num2;
myCallback(sum);
}
myCalculator(5, 5, myDisplayer);
</script>
</body>
</html>
.ﺖﺳﺍ ﻊﺑﺎﺗ ﮏﯾ ﻡﺎﻧ myDisplayer
،ﻻﺎﺑ ﻝﺎﺜﻣ ﺭﺩ
.ﺩﻮﺷ ﯽﻣ ﻝﺎﺳﺭﺍ myCalculator()
ﻪﺑ ﻥﺎﻣﻮﮔﺭﺁ ﻥﺍﻮﻨﻋ ﻪﺑ
.ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻥﺎﻣﺰﻤﻫﺎﻧ ﻊﺑﺍﻮﺗ ﺎﺑ ﺐﻠﻏﺍ ﯽﻧﺍﻮﺧﺍﺮﻓ ،ﯽﻌﻗﺍﻭ ﯼﺎﯿﻧﺩ ﺭﺩ
.ﺖﺳﺍ setTimeout()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﻟﻮﻤﻌﻣ ﻝﺎﺜﻣ ﮏﯾ
،setTimeout()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻊﺑﺎﺗ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻡﺎﮕﻨﻫ
setTimeout(myFunction, 3000);
function myFunction() {
document.getElementById("demo").innerHTML = "I love You !!";
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>
<h2>setTimeout() with a Callback</h2>
<p>Wait 3 seconds (3000 milliseconds) for this page to change.</p>
<h1 id="demo"></h1>
<script>
setTimeout(myFunction, 3000);
function myFunction() {
document.getElementById("demo").innerHTML = "I love You !!";
}
</script>
</body>
</html>
.ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺱﺎﻤﺗ ﻪﺑ ﺦﺳﺎﭘ ﻥﺍﻮﻨﻋ ﻪﺑ myFunction
،ﻻﺎ
.ﺪﯿﻨﮑﻧ ﻩﺩﺎﻔﺘﺳﺍ ﺰﺘﻧﺍﺮﭘ ﺯﺍ ﻪﮐ ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺩﺎﯾ ﻪﺑ ،ﺪﯿﻨﮐ ﯽﻣ ﻝﺎﺳﺭﺍ ﻥﺎﻣﻮﮔﺭﺁ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﯽﻌﺑ ؛setTimeout (myFunction، 3000) :ﺖﺳﺍﺭ ﺖﻤﺳ ;myFunction
ﻪﺑ ﻥﺎﻣﻮﮔﺭﺁ ﻥﺍﻮﻨﻋ ﻪﺑ ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ
setTimeout(myFunction(), 3000) :ﻩﺎﺒﺘﺷﺍ
،ﺮﮕﯾﺩ ﻊﺑﺎﺗ ﻪﺑ ﻥﺎﻣﻮﮔﺭﺁ ﻥﺍﻮﻨﻋ ﻪﺑ ﻊﺑﺎﺗ ﮏﯾ ﻡﺎﻧ ﻝﺎﺳﺭﺍ ﯼﺎﺟ ﻪﺑ
setTimeout(function() { myFunction("I love You !!!"); }, 3000);
function myFunction(value) {
document.getElementById("demo").innerHTML = value;
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>
<h2>setInterval() with a Callback</h2>
<p>Wait 3 seconds (3000 milliseconds) for this page to change.</p>
<h1 id="demo"></h1>
<script>
setTimeout(function() { myFunction("I love You !!!"); }, 3000);
function myFunction(value) {
document.getElementById("demo").innerHTML = value;
}
</script>
</body>
</html>
function(){ myFunction("I love you !!!"); }
،ﻻﺎﺑ ﻝﺎﺜ
ﻦﯾﺍﺮﺑﺎﻨﺑ ،ﺖﺳﺍ ﺕﻭﺍ ﻢﯾﺎﺗ ﺯﺍ ﻞﺒﻗ ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ ﺩﺍﺪﻌﺗ 3000
،setInterval()
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻊﺑﺎﺗ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻡﺎﮕﻨﻫ
setInterval(myFunction, 1000);
function myFunction() {
let d = new Date();
document.getElementById("demo").innerHTML=
d.getHours() + ":" +
d.getMinutes() + ":" +
d.getSeconds();
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>
<h2>setInterval() with a Callback</h2>
<p>Using setInterval() to display the time every second (1000 milliseconds).</p>
<h1 id="demo"></h1>
<script>
setInterval(myFunction, 1000);
function myFunction() {
let d = new Date();
document.getElementById("demo").innerHTML=
d.getHours() + ":" +
d.getMinutes() + ":" +
d.getSeconds();
}
</script>
</body>
</html>
.ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺱﺎﻤﺗ ﻪﺑ ﺦﺳﺎﭘ ﻥﺍﻮﻨﻋ ﻪﺑ myFunction
،ﻻﺎ
.ﺪﻨﻨﮐ ﻉﻭﺮﺷ ﺍﺭ ﺕﺪﻣ ﯽﻧﻻﻮﻃ ﯼﺎﻫﺭﺎﮐ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﻣﺎﻧﺮﺑ ،ﻥﺎﻣﺰﻤﻫﺎﻧ ﯽﺴﯾﻮﻧ ﻪﻣﺎﻧ .ﺖﺳﺍ ﺭﺍﻮﺷﺩ ﻥﺁ ﯽﯾﺍﺩﺯ ﻝﺎﮑﺷﺍ ﻭ ﺭﺍﻮﺷﺩ ﻥﺎﻣﺰﻤﻫﺎﻧ ﯼﺎﻫ ﻪﻣﺎﻧﺮﺑ ﻦﺘﺷﻮﻧ ،ﺎﻣﺍ .ﺪﻨﻨﮐﯽﻤﻧ ﻩﺩﺎﻔﺘﺳﺍ ﯽﺘﺸﮔﺮﺑ ﯼﺎﻫﺱﺎﻤﺗ ﺯﺍ ﻥﺭﺪﻣ ﻥﺎﻣﺰﻤﻫﺎﻧ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﺵﻭﺭ ﺮ .ﺪﺷ ﺪﯿﻫﺍﻮﺧ ﺎﻨﺷﺁ ﺎﻫ ﻩﺪﻋﻭ ﺎﺑ ﺵﺯﻮﻣﺁ ﻦﯾﺍ ﯼﺪﻌﺑ ﻞﺼﻓ ﺭﺩmyFunction
ﻪﺑ ﻥﺎﻣﻮﮔﺭﺁ ﻥﺍﻮﻨﻋ ﻪﺑ ﺱﺎﻤﺗ ﻪﺑ ﺦﺳﺎﭘ ﯼﺎﻫ ﻦﯾﺰﮕﯾﺎﺟ
ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ