.ﺪﻨﮐ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺍﺭ ﻥﺁ "ﯼﺰﯿﭼ" ﻪﮐ ﺩﻮﺷ ﯽﻣ ﺍﺮﺟﺍ ﯽﻧﺎﻣﺯ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺩﺮﮑﻠﻤﻋ<"code clas
.ﺩﻮﺷ ﯽﻤﻧ ﺍﺮﺟﺍ ﻊﺑﺎﺗ ﻞﺧﺍﺩ ﺪﮐ ،ﺪﺷﺎﺑ ﻒﯾﺮﻌﺗ ﻊﺑﺎﺗ ﯽﺘﻗﻭ
.ﺪﺷﺎﺑ ﯽﻧﺍﻮﺧﺍﺮﻓ ﻊﺑﺎﺗ ﻪﮐ ﺩﻮﺷ ﯽﻣ ﺍﺮﺟﺍ ﯽﻧﺎﻣﺯ ﻊﺑﺎﺗ ﮏﯾ ﻞﺧﺍﺩ ﺪﮐ
.ﺖﺳﺍ ﺞﯾﺍﺭ «ﻥﺩﺮﮐ ﺽﺮﻓ» ﯼﺎﺟ ﻪﺑ «ﻊﺑﺎﺗ ﮏﯾ ﻦﻔﻠﺗ» ﺕﺭﺎﺒﻋ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
ﺎﯾ "ﺩﺮﮐ ﻉﻭﺮﺷ ﺍﺭ ﻊﺑﺎﺗ ﮏﯾ" ، "ﺩﺮﮐ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺍﺭ ﻊﺑﺎﺗ ﮏﯾ" ﺪﻨﯾﻮﮔ ﯽﻣ ﻻًﻮﻤﻌﻣ ﻦﯿﻨﭽﻤﻫ
ﻒﻟﺍ ﺍﺮﯾﺯ ،ﺩﺮﮐ ﻢﯿﻫﺍﻮﺧ ﻩﺩﺎﻔﺘﺳﺍ ﺫﻮﻔﻧ ﺯﺍ ﺵﺯﻮﻣﺁ ﻦﯾﺍ ﺭﺩ
function myFunction(a, b) {
return a * b;
}
myFunction(10, 2); //
Will return 20
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>The global function (myFunction) returns the product of the arguments (a ,b):</p>
<p id="demo"></p>
<script>
function myFunction(a, b) {
return a * b;
}
document.getElementById("demo").innerHTML = myFunction(10, 2);
</script>
</body>
</html>
ﺩﺭﺍﺩ ﺩﻮﺟﻭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ ﺎﻣﺍ .ﺩﺭﺍﺪﻧ ﻖﻠﻌﺗ ﯽﺌﯿﺷ ﭻﯿﻫ ﻪﺑ ﻻﺎﺑ ﻊﺑﺎﺗ
ﺖﺳﺍ ﻥﺁ ﻪﺑ "ﻖﻠﻌﺘﻣ" ﻻﺎﺑ ﻊﺑﺎﺗ ﻦﯾﺍﺮﺑﺎﻨﺑ ،ﺖﺳﺍ HTML ﻪﺤﻔﺻ ﺩﻮﺧ ﺽﺮﻓﺶﯿﭘ ﯽﻧﺎﻬﺟ ﯽﺷ HTML ﺭﺩ
ﻻﺎﺑ ﻊﺑﺎﺗ .ﺖﺳﺍ ﺮﮔﺭﻭﺮﻣ ﻩﺮﺠﻨﭘ ،ﻪﺤﻔﺻ ﯽﺷ ﺮﮔﺭﻭﺮﻣ ﮏﯾ ﺭﺩ
.ﺖﺴﯿﻧ ﯽﺑﻮﺧ ﯽﻠﯿﺧ ﺵﻭﺭ ﺎﻣﺍ ،ﺖﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻊﺑﺎﺗ ﮏﯾ ﯽﻧﺍﻮﺧﺍﺮﻓ ﯼﺍﺮﺑ ﻝﻮﻤﻌﻣ ﺵﻭﺭ ﮏﯾ ﻦﯾﺍ
myFunction() ﻭ window.myFunction() ﺪﻨﺘﺴﻫ ﻊﺑﺎﺗ ﻥﺎﻤﻫ:
function myFunction(a, b) {
return a * b;
}
window.myFunction(10, 2); // Will also return 20
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>Global functions automatically become window methods. Invoking myFunction() is the same as invoking window.myFunction().</p>
<p id="demo"></p>
<script>
function myFunction(a, b) {
return a * b;
}
document.getElementById("demo").innerHTML = window.myFunction(10, 2);
</script>
</body>
</html>
.ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﺷ ﮏﯾ ﻪﺑ this
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ،ﺖﭙﯾﺮﮑﺳﺍ
ﻡﺍﺪﮐ (ﯽﻧﺍﻮﺧﺍﺮﻓ ﺎﯾ ﻩﺩﺎﻔﺘﺳﺍ) ﯽﻧﺍﻮﺧﺍﺮﻓ ﻩﻮﺤﻧ ﻪﺑ ﯽﮕﺘﺴﺑ ﯽﺷ :ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﻔﻠﺘﺨﻣ ءﺎﯿﺷﺍ ﻪﺑ ﻥﺁ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻩﻮﺤﻧ ﻪﺑ ﻪﺘﺴﺑ .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﺷ ﻪﺑ .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﻧﺎﻬﺟ ءﯽﺷ ﻪﺑ .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﻧﺎﻬﺟ ءﯽﺷ ﻪﺑ .ﺖﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻦﯾﺍ ﺵﺯﻮﻣﺁthis
ﻦﯾﺍ<"code class="w3-codespan> ،ﯽﺷ ﺵﻭﺭ ﮏﯾ ﺭﺩ
ﻦﯾﺍ<"code class="w3-codespan> ،ﯽﯾﺎﻬﻨﺗ ﻪﺑ
ﻦﯾﺍ<"code class="w3-codespan> ،ﻊﺑﺎﺗ ﮏﯾ ﺭﺩ
ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ<"code>
ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ
ﻦﯾﺍ
ﺭﺍﺪﻘﻣ ﺪﯿﻧﺍﻮﺗ ﯽﻤﻧ ﺎﻤﺷ .ﺖﺳﺍ ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﮏﯾ .ﺖﺴﯿﻧ ﺮﯿ :ﺪﯿﻨﯿﺒﺑ ﻦﯿﻨﭽﻤﻫ
this
ﺭﺍﺪﻘﻣ ،ﺩﻮﺷ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﮏﻟﺎﻣ ﯽﺷ ﻥﻭﺪﺑ ﯽﻌﺑﺎﺗ ﯽﺘﻗﻭ
.ﺖﺳﺍ ﺮﮔﺭﻭﺮﻣ ﻩﺮﺠﻨﭘ ،ﯽﻧﺎﻬﺟ ﯽﺷ ،ﺏﻭ ﺮﮔﺭﻭﺮﻣ ﮏﯾ ﺭﺩ
:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ this
ﺭﺍﺪﻘﻣ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﻩﺮﺠﻨﭘ ﯽﺷ ﻝﺎﺜﻣ ﻦﯾ
let x = myFunction();
// x will be the window object
function myFunction() {
return this;
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>In HTML the value of <b>this</b>, in a global function, is the window object.</p>
<p id="demo"></p>
<script>
let x = myFunction();
function myFunction() {
return this;
}
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
.ﺪﺷﺎﺑ ﯼﺮﺳﺍﺮﺳ ﯽﺷ this ﺭﺍﺪﻘﻣ ﻪﮐ ﺩﻮﺷ ﯽﻣ ﺚﻋﺎﺑ ،ﯼﺮﺳﺍﺮﺳ ﻊﺑﺎﺗ ﮏﯾ ﻥﺍﻮﻨﻋ
.ﺪﯿﻨﮐ ﻒﯾﺮﻌﺗ ﯽﺷ ﯼﺎﻫﺪﺘﻣ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﻊﺑﺍﻮﺗ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ
ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﻭﺩ ﺎﺑ (myObject) ﯽﺷ ﮏﯾ ﺮﯾﺯ ﻝﺎﺜﻣ
const myObject = {
firstName:"John",
lastName: "Doe",
fullName: function () {
return this.firstName + " " + this.lastName;
}
}
myObject.fullName(); // Will return "John Doe"
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>myObject.fullName() will return John Doe:</p>
<p id="demo"></p>
<script>
const myObject = {
firstName:"John",
lastName: "Doe",
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
document.getElementById("demo").innerHTML = myObject.fullName();
</script>
</body>
</html>
ﻪﺑ ﻖﻠﻌﺘﻣ ﻊﺑﺎﺗ .ﺖﺳﺍ ﻊﺑﺎﺗ ﮏﯾ fullName ﺵﻭﺭ
ﻪﮐ ﺖﺳﺍ ﯽﺌﯿﺷ ،ﺩﻮﺷ ﯽﻣ ﻩﺪﯿﻣﺎﻧ this
ﻪﮐ ﯼﺰﯿﭼ
:ﺪﯿﻧﺍﺩﺮﮔﺮﺑ ﺍﺭ this
ﺭﺍﺪﻘﻣ ﺎﺗ ﺪﯿﻫﺩ ﺮﯿﯿﻐﺗ ﺍﺭ fu
const myObject = {
firstName:"John",
lastName: "Doe",
fullName: function () {
return this;
}
}
// This will return [object Object] (the owner object)
myObject.fullName();
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>The value of <b>this</b>, in an object method, is the owner object.</p>
<p id="demo"></p>
<script>
const myObject = {
firstName:"John",
lastName: "Doe",
fullName: function() {
return this;
}
}
document.getElementById("demo").innerHTML = myObject.fullName();
</script>
</body>
</html>
.ﺩﻮﺷ ﯽﻣ this
ﺭﺍﺪﻘﻣ ﺚﻋﺎﺑ ،ﯽﺷ ﺪﺘﻣ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﻊﺑﺎﺗ ﮏﯾ
،ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺩﻮﺟﻭ new
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ،ﻊﺑﺎﺗ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺯﺍ ﻞﺒ
ﺪﻨﺘﺴﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻊﺑﺍﻮﺗ ﻪﮐ ﯽﯾﺎﺠﻧﺁ ﺯﺍ ﺎﻣﺍ ،ﺪﯿﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﯾﺪﺟ ﻊﺑﺎﺗ ﮏﯾ ﺎﻤﺷ ﻪﮐ ﺪﺳﺭ ﯽﻣ ﺮ
// This is a function constructor:
function myFunction(arg1, arg2) {
this.firstName = arg1;
this.lastName = arg2;
}
// This creates a new object
const myObj = new myFunction("John", "Doe");
// This will return "John"
myObj.firstName;
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>In this example, myFunction is a function constructor:</p>
<p id="demo"></p>
<script>
function myFunction(arg1, arg2) {
this.firstName = arg1;
this.lastName = arg2;
}
const myObj = new myFunction("John","Doe")
document.getElementById("demo").innerHTML = myObj.firstName;
</script>
</body>
</html>
ﺩﺮﺑ ﯽﻣ ﺙﺭﺍ ﻪﺑ ﺪﯾﺪﺟ ﯽﺷ .ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﯾﺪﺟ ﯽﺷ ﮏﯾ ﻩﺪﻧﺯﺎﺳ ﻥﺍﻮﺧﺍﺮﻓ ﮏﯾ
.ﺩﺭﺍﺪﻧ ﯼﺭﺍﺪﻘﻣ ﻩﺪﻧﺯﺎﺳ ﺭﺩ ﻦﯾﺍ<"code class="w3-codespan> ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ