.ﺪﻧﺪﺷ ﯽﻓﺮﻌﻣ ES6 ﺭﺩ ﻥﺎﮑﯿﭘ ﻊﺑﺍﻮﺗ
:ﻢﯿﺴﯾﻮﻨﺑ ﯼﺮﺗﻩﺎﺗﻮﮐ ﺩﺮﮑﻠﻤﻋ ﻮﺤﻧ ﺎﺗ ﺪﻨﻫﺩﯽﻣ ﻩﺯﺎﺟﺍ ﺎﻣ ﻪﺑ ﻥﺎﮑﯿﭘ ﻊﺑﺍﻮﺗ
let myFunction = (a, b) => a * b;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>
<h2>The Arrow Function</h2>
<p>This example shows the syntax of an Arrow Function, and how to use it.</p>
<p id="demo"></p>
<script>
let myFunction = (a, b) => a * b;
document.getElementById("demo").innerHTML = myFunction(4, 5);
</script>
</body>
</html>
hello = function() {
return "Hello World!";
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>
<p>This example shows the syntax of a function, without the use of arrow function syntax.</p>
<p id="demo"></p>
<script>
let hello = "";
hello = function() {
return "Hello World!";
}
document.getElementById("demo").innerHTML = hello();
</script>
</body>
</html>
hello = () => {
return "Hello World!";
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>
<h2>The Arrow Function</h2>
<p>This example shows the syntax of an Arrow Function, and how to use it.</p>
<p id="demo"></p>
<script>
let hello = "";
hello = () => {
return "Hello World!";
}
document.getElementById("demo").innerHTML = hello();
</script>
</body>
</html>
ﺕﺭﺎﺒﻋ ﻥﺁ ﻭ ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺭﻮﺘﺳﺩ ﮏﯾ ﻂﻘﻓ ﻊﺑﺎﺗ ﺮﮔﺍ !ﺩﻮﺷ ﯽﻣ ﺮﺗ ﻩﺎﺗﻮﮐ
hello = () => "Hello World!";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>
<h2>The Arrow Function</h2>
<p>This example shows an Arrow Function without the brackets or the return keyword.</p>
<p id="demo"></p>
<script>
let hello = "";
hello = () => "Hello World!";
document.getElementById("demo").innerHTML = hello();
</script>
</body>
</html>
ﻪﺟﻮﺗ: ﯽﻣ ﺭﺎﮐ ﯽﺗﺭﻮﺻ ﺭﺩ ﻂﻘﻓ ﻦﯾﺍﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﮏﯾ ﻂﻘﻓ ﻊﺑﺎﺗ ﻪﮐ ﺪﻨﮐ
:ﺪﯿﻫﺩ ﯽﻣ ﺭﺍﺮﻗ ﺰﺘﻧﺍﺮﭘ ﻞﺧﺍﺩ ﺭﺩ ﺍﺭ ﺎﻬﻧﺁ ،ﺪﯾﺭﺍﺩ ﯽﯾﺎﻫﺮﺘﻣﺍﺭﺎﭘ ﺮﮔﺍ
hello = (val) => "Hello " + val;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>
<h2>The Arrow Function</h2>
<p>This example shows an Arrow Function with a parameter.</p>
<p id="demo"></p>
<script>
let hello = "";
hello = (val) => "Hello " + val;
document.getElementById("demo").innerHTML = hello("Universe!");
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﺮﻈﻧ ﻑﺮﺻ ﺰﯿﻧ ﺰﺘﻧﺍﺮﭘ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ،ﺪﯾﺭﺍﺩ ﺮﺘﻣﺍﺭﺎﭘ ﮏﯾ ﻂﻘﻓ ﺮﮔﺍ ،ﻊﻗﺍﻭ ﺭﺩ
hello = val => "Hello " + val;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>
<h2>The Arrow Function</h2>
<p>This example shows that if you have only one parameter in an Arrow Function, you can skip the parentheses.</p>
<p id="demo"></p>
<script>
let hello = "";
hello = val => "Hello " + val;
document.getElementById("demo").innerHTML = hello("Universe!");
</script>
</body>
</html>
ﻦﯾﺍ<"code class="w3-codespan> ﻩﺭﺎﺑﺭﺩ.ﺖﺳﺍ ﺕﻭﺎﻔﺘﻣ ﯽﻟﻮﻤﻌﻣ ﺎﺑ ﻪﺴﯾﺎﻘﻣ ﺭﺩ ﻥﺎﮑﯿﭘ ﯼﺎﻫﺩﺮﮑﻠﻤﻋ ﺭﺩ ﺰﯿﻧ ﻦﯾﺍ<"code class="w3-cod
ﺩﺭﺍﺪﻧ ﺩﻮﺟﻭ ﯽﻟﺎﺼﺗﺍ ﭻﯿﻫ ﺶﻠﻓ ﻊﺑﺍﻮﺗ ﺎﺑ ،ﻪﺻﻼﺧ ﺭﻮﻃ ﻪﺑ
ﻪﮐ ﺖﺳﺍ ﯽﺌﯿﺷ ﻩﺪﻨﻫﺩ ﻥﺎﺸﻧ ﻦﯾﺍ<"code class="w3-codespan> ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ،ﻢﻈﻨﻣ ﻊﺑﺍﻮﺗ ﺭﺩ
ﻩﺪﻨﻫﺩ ﻥﺎﺸﻧ ﻪﺸﯿﻤﻫ ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﻦﯾﺍ<"code class="w3-codespan> ،ﻥﺎﮑﯿﭘ ﻊﺑﺍﻮ
.ﻢﯾﺯﺍﺪﻨﯿﺑ ﯽﻫﺎﮕﻧ ﻝﺎﺜﻣ ﻭﺩ ﻪﺑ ﺕﻭﺎﻔﺗ ﮎﺭﺩ ﯼﺍﺮﺑ ﺪﯿﻫﺩ ﻩﺯﺎﺟﺍ
ﺮﮕﯾﺩ ﺭﺎﺑ ﮏﯾ ﻭ ﻪﺤﻔﺻ ﯼﺭﺍﺬﮔﺭﺎﺑ ﻡﺎﮕﻨﻫ ﻝﻭﺍ ،ﺪﻨﻨﮐ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺭﺎﺑ ﻭﺩ ﺍﺭ ﺪﺘﻣ ﮏﯾ ﻝﺎﺜﻣ ﻭﺩ ﺮﻫ
ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻊﺑﺎﺗ ﮏﯾ ﺯﺍ ﻡﻭﺩ ﻝﺎﺜﻣ ﻭ ﻢﻈﻨﻣ ﻊﺑﺎﺗ ﮏﯾ ﺯﺍ ﻝﻭﺍ ﻝﺎﺜﻣ
.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ (ﻪﻤﮐﺩ ﻭ ﻩﺮﺠﻨﭘ) ﺕﻭﺎﻔﺘﻣ ﯽﺷ ﻭﺩ ﻝﻭﺍ ﻝﺎﺜﻣ ﻪﮐ ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﻪﺠﯿﺘﻧ
ﻩﺪﻨﻫﺩ ﻥﺎﺸﻧ ﻦﯾﺍ<"code class="w3-codespan> ﯽﻟﻮﻤﻌﻣ ﻊﺑﺎﺗ ﮏﯾ ﺎﺑ
// Regular Function:
hello = function() {
document.getElementById("demo").innerHTML
+= this;
}
// The window object calls the function:
window.addEventListener("load", hello);
// A button object calls the
function:
document.getElementById("btn").addEventListener("click", hello);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript "this"</h1>
<p>This example demonstrate that in a regular function, the "this" keyword represents different objects depending on how the function was called.</p>
<p>Click the button to execute the "hello" function again, and you will see that this time "this" represents the button object.</p>
<button id="btn">Click Me!</button>
<p id="demo"></p>
<script>
let hello = "";
hello = function() {
document.getElementById("demo").innerHTML += this;
}
//The window object calls the function:
window.addEventListener("load", hello);
//A button object calls the function:
document.getElementById("btn").addEventListener("click", hello);
</script>
</body>
</html>
ﻩﺪﻨﻫﺩ ﻥﺎﺸﻧ ﻦﯾﺍ<"code class="w3-codespan> ﻥﺎﮑﯿﭘ ﻊﺑﺎﺗ ﮏﯾ ﺎﺑ
// Arrow Function:
hello = () => {
document.getElementById("demo").innerHTML
+= this;
}
// The window object calls the function:
window.addEventListener("load", hello);
// A button object calls the
function:
document.getElementById("btn").addEventListener("click", hello);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript "this"</h1>
<p>This example demonstrate that in Arrow Functions, the "this" keyword represents the object that owns the function, no matter who calls the function.</p>
<p>Click the button to execute the "hello" function again, and you will see that "this" still represents the window object.</p>
<button id="btn">Click Me!</button>
<p id="demo"></p>
<script>
let hello = "";
hello = () => {
document.getElementById("demo").innerHTML += this;
}
//The window object calls the function:
window.addEventListener("load", hello);
//A button object calls the function:
document.getElementById("btn").addEventListener("click", hello);
</script>
</body>
</html>
ﺕﺎﻗﻭﺍ ﯽﻫﺎﮔ .ﺪﯾﺭﺎﭙﺴﺑ ﺮﻃﺎﺧ ﻪﺑ ﺍﺭ ﺎﻫ ﺕﻭﺎﻔﺗ ﻦﯾﺍ ،ﺪﯿﻨﮐ ﯽﻣ ﺭﺎﮐ ﻊﺑﺍﻮﺗ ﺎﺑ ﻪﮐ ﯽﻣﺎﮕﻨﻫ
ﺪﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ ﺍﺭ ﻞﻣﺎﮐ ﯽﻧﺎﺒﯿﺘﺸﭘ ﺎﺑ ﺮﮔﺭﻭﺮﻣ ﯼﺎﻫ ﻪﺨﺴﻧ ﻦﯿﻟﻭﺍ ﺮﯾﺯ ﻝﻭﺪﺟ
Chrome 45 | Edge 12 | Firefox 22 | Safari 10 | Opera 32 |
Sep, 2015 | Jul, 2015 | May, 2013 | Sep, 2016 | Sep, 2015 |