.ﺪﺷﺎﺑ ﻩﺩﺎﻔﺘﺳﺍ ﻞﺑﺎﻗ ﻒﻠﺘﺨﻣ ﺩﺭﺍﻮﻣ ﺭﺩ ﻪﮐ ﺪﯿﺴﯾﻮﻨﺑ ﯼﺪﺘﻣ ﺪﯿﻧﺍﻮﺗﯽﻣ ، .ﺪﻨﺘﺴﻫ ﯽﺷ ﯼﺎﻫﺪﺘﻣ ﻊﺑﺍﻮﺗ ﻪﻤﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ ﺖﺳﺍ ﯽﺷ ﺯﺍ ﯽﻌﺑﺎﺗ ،ﺪﺷﺎﺒﻧ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﺪﺘﻣ ﻊﺑﺎﺗ ﮏﯾ ﺮﮔﺍ ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ 3 ﺎﺑ ﯽﺷ ﮏﯾ ﺮﯾﺯ ﻝﺎﺜﻣ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﺺﺨﺷ ءﯽﺷ ﻪﺑ this.firstName ﯽﮔﮋﯾﻭ ﯼﺎﻨﻌﻣ ﻪﺑ firstName thi :ﻞﺜﻣ this.firstName ﯽﮔﮋﯾﻭ ﯼﺎﻨﻌﻣ ﻪﺑ firstName per .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﺷ ﮏﯾ ﻪﺑ ﻡﺍﺪﮐ (ﯽﻧﺍﻮﺧﺍﺮﻓ ﺎﯾ ﻩﺩﺎﻔﺘﺳﺍ) ﯽﻧﺍﻮﺧﺍﺮﻓ ﻩﻮﺤﻧ ﻪﺑ ﯽﮕﺘﺴﺑ ﯽﺷ :ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﻔﻠﺘﺨﻣ ءﺎﯿﺷﺍ ﻪﺑ ﻥﺁ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻩﻮﺤﻧ ﻪﺑ ﻪﺘﺴﺑ .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﺷ ﻪﺑ .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﻧﺎﻬﺟ ءﯽﺷ ﻪﺑ .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﻧﺎﻬﺟ ءﯽﺷ ﻪﺑ .ﺖﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻦﯾﺍ ﺵﺯﻮﻣﺁ ﺪﻨﺘﺴﻫ ﺵﻭﺭ ﻊﺑﺍﻮﺗ ﻪﻤﻫ
ﻝﺎﺜﻣ
const person = {
firstName:"John",
lastName: "Doe",
fullName: function () {
return this.firstName + " " + this.lastName;
}
}
// This will return "John Doe":
person.fullName();
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>This example creates an object with 3 properties (firstName, lastName, fullName).</p>
<p>The fullName property is a method:</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>
this
،ﻻﺎﺑ ﻝﺎﻦﯾﺍ ؟ﺖﺴﯿﭼ
this
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ،ﺖﭙﯾﺮﮑﺳﺍthis
ﻦﯾﺍ<"code class="w3-codespan> ،ﯽﺷ ﺵﻭﺭ ﮏﯾ ﺭﺩ
ﻦﯾﺍ<"code class="w3-codespan> ،ﯽﯾﺎﻬﻨﺗ ﻪﺑ
ﻦﯾﺍ<"code class="w3-codespan> ،ﻊﺑﺎﺗ ﮏﯾ ﺭﺩ
ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ<"code>
ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ
ﻦﯾﺍ
ﺭﺍﺪﻘﻣ ﺪﯿﻧﺍﻮﺗ ﯽﻤﻧ ﺎﻤﺷ .ﺖﺳﺍ ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﮏﯾ .ﺖﺴﯿﻧ ﺮﯿ :ﺪﯿﻨﯿﺒﺑ ﻦﯿﻨﭽﻤﻫ
ﺖﺳﺍ ﻩﺪﺷ ﻒﯾﺮﻌﺗ ﺶﯿﭘ ﺯﺍ ﺵﻭﺭ ﮏﯾ call()
ﺵﻭﺭ
ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺪﺘﻣ ﮏﯾ ﯽﻧﺍﻮﺧﺍﺮﻓ ﯼﺍﺮﺑ ﻥﺁ ﺯﺍ ﻥﺍﻮﺗ ﯽﻣ
.ﺪﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺮﮕﯾﺩ ﯽﺷ ﮏﯾ ﻪﺑ ﻖﻠﻌﺘﻣ ﯼﺪﺘﻣ ﺯﺍ ﺪﻧﺍﻮﺗ ﯽﻣ ﯽﺷ ﮏﯾ ،ca
ﺪﻨﮐﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺍﺭ ﺩﺮﻓ fullName ﺵﻭﺭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﻝﺎﺜﻣ ﻦﯾﺍ
const person = {
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
const person1 = {
firstName:"John",
lastName: "Doe"
}
const person2 = {
firstName:"Mary",
lastName: "Doe"
}
// This will return "John Doe":
person.fullName.call(person1);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>This example calls the fullName method of person, using it on person1:
</p>
<p id="demo"></p>
<script>
const person = {
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
const person1 = {
firstName:"John",
lastName: "Doe"
}
const person2 = {
firstName:"Mary",
lastName: "Doe"
}
document.getElementById("demo").innerHTML = person.fullName.call(person1);
</script>
</body>
</html>
ﺪﻨﮐﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺍﺭ ﺩﺮﻓ fullName ﺵﻭﺭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﻝﺎﺜﻣ ﻦﯾﺍ
const person = {
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
const person1 = {
firstName:"John",
lastName: "Doe"
}
const person2 = {
firstName:"Mary",
lastName: "Doe"
}
// This will return "Mary Doe"
person.fullName.call(person2);
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>This example calls the fullName method of person, using it on person2:</p>
<p id="demo"></p>
<script>
const person = {
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
const person1 = {
firstName:"John",
lastName: "Doe"
}
const person2 = {
firstName:"Mary",
lastName: "Doe"
}
document.getElementById("demo").innerHTML = person.fullName.call(person2);
</script>
</body>
</html>
:ﺩﺮﯾﺬﭙﺑ ﺍﺭ ﺎﻫﻥﺎﻣﻮﮔﺭﺁ ﺪﻧﺍﻮﺗﯽﻣ call()
ﺪﺘﻣ
const person = {
fullName: function(city, country) {
return this.firstName + " " + this.lastName
+ "," + city + "," + country;
}
}
const person1 = {
firstName:"John",
lastName: "Doe"
}
person.fullName.call(person1, "Oslo", "Norway");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>This example calls the fullName method of person, using it on person1:
</p>
<p id="demo"></p>
<script>
const person = {
fullName: function(city, country) {
return this.firstName + " " + this.lastName + "," + city + "," + country;
}
}
const person1 = {
firstName:"John",
lastName: "Doe"
}
const person2 = {
firstName:"Mary",
lastName: "Doe"
}
document.getElementById("demo").innerHTML = person.fullName.call(person1, "Oslo", "Norway");
</script>
</body>
</html>